Okay, I hope I can explain this correctly.
I need to set up a scheduling app of sorts.
What I will do is take say 4 People, and try to match these 4 people up in unique pairs each day, for some activity.
I need to print out these possible pairings.
The condition is for, say, the following three (4) people:
Adam, Carol, Dave, and Ed:
Day(1): Adam - Carol
Day(2): Adam - Dave
Day(3): Adam - Ed
Day(4): Carol - Dave
Day(5): Carol - Ed
Day(6): Dave - Ed
(Note: Adam - Carol is the same as the pair Carol - Adam)
I know that this is simply using Combinations and the formula:
[sub]n[/sub]C[sub]r[/sub] = n! [÷] ( (n-r)!r! )
I have a function:
and the formula for combinations:
As an example I am hardcoding n=4 and r=2 here for simplicity's sake:
Which returns 6, which is correct.
I am having trouble incorporating this into the application to print out the 6 pairs shown above.
Can someone show me how to do this? I am sure it uses arrays.
It must work for any number of people that might sign up for a class.
Thank you in advance,
Chalmers
I need to set up a scheduling app of sorts.
What I will do is take say 4 People, and try to match these 4 people up in unique pairs each day, for some activity.
I need to print out these possible pairings.
The condition is for, say, the following three (4) people:
Adam, Carol, Dave, and Ed:
Day(1): Adam - Carol
Day(2): Adam - Dave
Day(3): Adam - Ed
Day(4): Carol - Dave
Day(5): Carol - Ed
Day(6): Dave - Ed
(Note: Adam - Carol is the same as the pair Carol - Adam)
I know that this is simply using Combinations and the formula:
[sub]n[/sub]C[sub]r[/sub] = n! [÷] ( (n-r)!r! )
I have a function:
Code:
function factorial(n)
if n <= 1 then
factorial = 1
else
factorial=n * factorial( n - 1 )
end if
end function
and the formula for combinations:
As an example I am hardcoding n=4 and r=2 here for simplicity's sake:
Code:
factorial(4)/(factorial(4-2)*factorial(2))
I am having trouble incorporating this into the application to print out the 6 pairs shown above.
Can someone show me how to do this? I am sure it uses arrays.
It must work for any number of people that might sign up for a class.
Thank you in advance,
Chalmers