# Unshuffling

The perfect shuffle is a difficult maneuver, requiring a magician to cut a deck of cards exactly in half and then shuffle so that two halves are perfectly interwoven. As a way of rearranging a deck of cards, the perfect shuffle has many interesting mathematical properties, but not just anyone can take advantage of these properties to perform magic tricks—the shuffle is just too hard to master.

In the video below, mathematician Doug Ensley and two students demonstrate a trick based on a simpler way of mixing cards that has the same properties as the perfect shuffle.

Here is an explanation:

# Taking it Further

Ensley’s sorting of the deck into two piles in an alternating fashion and then re-stacking the two piles into a single packet is what he calls the perfect unshuffle. And a moment’s thought should convince you that this is a good name; it is a backwards version of the perfect shuffle.

Although the trick is illustrated with 10 cards in the original packet, it works the same way with any even number of cards.

A great advantage of the perfect unshuffle over the perfect shuffle is its great generalizability. If you can deal the cards into two piles, then you have the skill to deal the cards into three piles... or more! After mastering the trick with the two-pile unshuffle, try doing the trick with 12 cards and allow the volunteer to deal the cards into two, three, four, or six piles. (In each case the piles should be picked up left-to-right or right-to-left—not randomly!) Is central symmetry (as discussed in the second video) maintained by any of these shuffles? Can you prove it?

# The Underlying Mathematics

While this trick works with any even number of cards, for our explanation we will stick with 10 cards to keep it simple.

One can derive a formula for the location of the card initially at position x from the top. The top card will be considered to be in position 0. Note that there are really two shuffles in this problem, dependent on which pile is placed on top when the cards are regathered.

We can use the symbol E for the shuffle where the original Even positioned cards are gathered on top of the original odd position cards, and we use the symbol U for the shuffle where the original odd (i.e., Uneven) positioned cards are gathered on top of the original even position cards.

For example, in shuffle U, the card at position x before the shuffle is in position 4x mod 9 after the shuffle, for all x other than 0. (The card originally in position 0 goes to the bottom, position 9.) A before and after table of values for this example with 10 cards illustrates the correctness of this formula:

 Position before 0 1 2 3 4 5 6 7 8 9 Position after 9 4 8 3 7 2 6 1 5 0

In this example, a pair of cards whose initial positions sum to 9 are symmetric to one another relative to the center of the packet—specifically, pairs {0, 9}, {1,8}, {2,7}, {3,6}, and {4,5} identify centrally symmetric positions before the shuffle. It is easy to see from the table above that these pairs end up in centrally symmetric positions after the shuffle as well. A rigorous proof uses the fact that if (x + y) mod 9 = 0, then (4x + 4y) mod 9 = 0, a simple consequence of the fact that gcd(4, 9) = 1. This rigorous approach easily extends to the general case with 2n cards.

For the record, in shuffle E, the card in position x before the shuffle is in position (5x + 4) mod 11 after the shuffle. Generalizing these formulas for 2n cards is a great exercise in working with modular arithmetic. The fact that the formula is always linear should be enough of a starting hint.

There are several books that give a good explanation of the various mathematical properties of the perfect shuffle, including Brent Morris’s classic, Magic Tricks, Card Shuffling, and Dynamic Computer Memories (MAA, 1998) and the much newer Magical Mathematics: The Mathematical Ideas That Animate Great Magic Tricks by Diaconis and Graham (Princeton University Press, 2011). This book includes much more than their 1983 paper, “The Mathematics of Perfect Shuffles,” which appeared in Advances in Applied Mathematics (vol. 4, pp 175–196).

The best reference for the perfect unshuffle is Doug Ensley’s paper, “Unshuffling for the Imperfect Mathematician,” which appeared in Math Horizons (February 2004). It discusses the perfect unshuffle further and provides other magic tricks that use its properties.

Here are some online mathematical card tricks you can try. The applets linked below will run in any browser that supports Adobe Flash Player.

Special thanks to Simon Neubauer for making our videos!