Quote:
Assign each card in the ordered deck a number.
Code:
Encode:
Set V = 0
Set M = 52
For each card
Add number to V
Multiply V by M
Decrement M
Renumber deck
To decode you repeatedly calculate the divisor and remainder of V / (decreasing factorials) adjusting the resulting numbers as the deck builds up and assigning the remainder to V at each stage.
That was just off the top of my head. I might be able to design a better algorithm if I spent some time on it but it's so pointless that it's not really worth the effort.
Sorry, maybe missing something but doesn't that use more than 226 bits to encode a deck? It seems like it uses even more than the naive 249 bit method.
Just so we're on the same page, suppose my shuffled deck is the exact reverse of the ordered deck. The ordered deck goes 2c,....Ac,2d,....,Ad,2h,....,Ah,2s,.....As for the sake of argument. 2c is card 1, As is card 52 = 110100 in binary.
I look at my first card, its the As.
V+52 = 52, multiply by M = 2704, decrement M to 51. Next card is Ks, card 51, 2704+51 = 2755 * 51 = 140505. The end number is going to be bigger than 52!, so bigger than 2^226, and likely much bigger...
For a deck of four cards, 4321 is encoded as 119 which is 7 bits in binary, whereas 4 card decks can theoretically be encoded in 5 bits as 4! = 24 < 32.