Microsoft Office Tutorials and References
In Depth Information
LIST COMBINATIONS OF N ITEMS TAKEN M AT A TIME
possible to get “1 2 4” and “1 2 5” in subsequent calls. When “1 2 5” is obtained,
the next call by Comb2 n, m, k + 1 , s is done with m=1 and k=6.
These values of m and k satisfy the condition for If m > n - k + 1 Then Exit
Function because 1 > 5 – 6 + 1 and the call to the function exits, signifying
the end of the loop for combinations for 12* .
The function thus continues to run, building the combinations for 13* , 14* ,
23* , 24* , and 34* , and it fi nally exits to the Sub Combinations function from
which it was fi rst called, and a message box says that 10 combinations were
generated.
An easy way to monitor the fl ow of calculations is to uncomment the line Debug.
Print m, k, s in the code for Comb2 and watch the output in the immediate
window:
m
Part
3
k
s
3 1
2 2 1
1 3 1 2
0 4 1 2 3
1 4 1 2
0 5 1 2 4
1 5 1 2
0 6 1 2 5
1 6 1 2
2 3 1
1 4 1 3
0 5 1 3 4
1 5 1 3
0 6 1 3 5
1 6 1 3
2 4 1
1 5 1 4
0 6 1 4 5
1 6 1 4
2 5 1
3 2
2 3 2
 
Search JabSto ::




Custom Search