Home > Mathematica, Mathematics > Playing with a full deck: solution (illustration)

## Playing with a full deck: solution (illustration)

The algorithm for revealing the four cards in the solution explanation post can be summarized as follows:

1. Pick a pair of  cards of the repeated suits (guaranteed by the pigeonhole principle).
2. Chose the hidden card as the card $\leq$6 cards from the first card (guaranteed by modular arithmetic).
3. Lexicographically order the remaining three cards to code the number of cards ahead of the first card the hidden card sits.

I used Mathematica to:

• import and process the card images
• to map cards to  suits and values
• to encode the algorithm above (with assumptions about hidden ahead or behind (  difference  between first card and hidden card positions as  [hidden -first] was used) and the suit ranking: club < diamond < heart < spade)
• to randomly select 5 cards from deck without replacement and visualize algorithm to illustrate it

I stress the choice of cards ahead/behind and suit rankings (24 possible) are arbitrary. They must be agreed upon between the magician and the assistant prior to the trick.

Click on the image to enlarge.