Rod Pemberton wrote:
>
> Houston, we have a problem... It appears that's combinations
(un-ordered
> set).
>
Right, nPm = n!/(n-m)!.
> A deck order of 1,2,3,4,5 is distinctly different from a deck order of
> 2,5,4,1,3. The game needs to keep track of the deck order. The
remaining
> five cards could be 1,50,23,37,9. I'd think we'd want permutations
(ordered
> sets). For 52 cards:
>
> 52!=52*51*... = (big number Wolf posted)
>
> For five cards remaining:
>
> 5*4*3*2*1 / 1! = 120
>
> So, I asked: if 1,2,3,4,5 is ranked as first of 120 permutations of
> 1,2,3,4,5, and all permutations are ranked from 1 to 120, what
permutation
> out of 120 is 2,5,4,1,3? (I used example value 33.) Is there a way to
> generate the permutation from this rank number? Or, vice versa?
There is, it's just awkward.
In the case of the card deck, take the permutation number P:
Make a list, deck[] of all the cards.
card[0] = deck[P mod 52]
P <- P div 52
Remove card[0] from deck[].
card[1] = P mod 51
P <- P div 51
Remove card[1] from deck[].
.... and so on.
In practice, a list representation is much easier.
-hpa


|