More generally, the formula for finding the number of combinations of k objects you can choose from a set of n objects is:
n!
n_C_k = ---------------
k! (n - k)!
Combinations & Permutations Programs
The Algorithm For N-Choose-R in High Level Pseudocode:
Let k = min (r, n-r)
Start answer = 1
Start multiplier = n
Start divisor = 1
while divisor<= k do
{ answer = ( answer * multiplier ) div divisor # this will evenly divide
decrement the multiplier
increment the divisor
}
n!
n_C_k = ---------------
k! (n - k)!
Combinations & Permutations Programs
The Algorithm For N-Choose-R in High Level Pseudocode:
Let k = min (r, n-r)
Start answer = 1
Start multiplier = n
Start divisor = 1
while divisor<= k do
{ answer = ( answer * multiplier ) div divisor # this will evenly divide
decrement the multiplier
increment the divisor
}
<< Home