- A loop to iterate through all 52 choose 7 combinations of cards:
- for(c1 = 0; c1 < 52; c1++) {
- for(c2 = c1 + 1; c2 < 52; c2++) {
- for(c3 = c2 + 1; c3 < 52; c3++) {
- for(c4 = c3 + 1; c4 < 52; c4++) {
- for(c5 = c4 + 1; c5 < 52; c5++) {
- for(c6 = c5 + 1; c6 < 52; c6++) {
- for(c7 = c6 + 1; c7 < 52; c7++) {
- permutationIndex++;
- }}}}}}}
- The first iterations of this loop will give the values:
- c1 c2 c3 c4 c5 c6 c7 Permutation Index
- 0 1 2 3 4 5 6 0
- 0 1 2 3 4 5 7 1
- 0 1 2 3 4 5 8 2
- 0 1 2 3 4 5 9 3
- The format of the loop ensures that the representation of the 7 cards is always is ascending order.
- Problem: Given a set of 7 ordered integers, how do we find out their permutation index?
Posted by Anonymous on Thu 21st Dec 15:35
View followups from Anonymous | download | new post
Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.