code to write out combinations e.g. (10 choose 3)

Stellaferox

Active Member
Licensed User
Hi,

Related to my last question is the following. Does anyone have code to write out every possible combination (not permutation) from a given number X taken out Y (X choose Y)?
Any help appreciated. i just cannot seem to get the appropriate number written out.
Thx
Marc
 

derez

Expert
Licensed User
Longtime User
combination

Here is conceptual code, not debugged:
sub combination(x,y)
a = 1
for i = 1 to x
a = a*i
next
b = 1
for i = 1 to y
b=b*i
next
c=1
for i = 1 to x-y
c= c*i
next
return a/(b*c)
end sub
 

derez

Expert
Licensed User
Longtime User
Okay, I took the challenge !
see the attached program, both displaying and storing in a file.
fill the a out of b and press go. you will get the number of combinations and the last one, and you can brouse up and down.:)
 
Last edited:
Top