## The magic of shuffling

How do you shuffle a pack of cards? Our shuffling is very unimpressive, we've even been known to resort to jumbling them around in a big pile on the table. But good news – here is how you shuffle like a professional!

### How to shuffle perfectly

Take a pack of cards and split the pack into two equal halves (we're assuming your pack, like an ordinary 52-card pack, has an even number of cards). Now interleave them perfectly: top card from the first pile, top card from the second pile, next card from the first pile, next card from the second pile and so on. This is exact interleaving of two halves of the pack is called a *perfect shuffle*.

Will Houstoun demonstrating a perfect shuffle (Video: Will Houstoun)

After a perfect shuffle, your pack will be shuffled in one of two ways. If the first pile was the top half of the pack, then the top card of your shuffled pack will be the top card of the original pack, and the bottom card of the shuffled pack will be the bottom card of the original pack. This is called an *out-shuffle*, and it fixes the top and bottom cards of the pack, they remain in their original position, while the other cards are interleaved.

If, like us, you are not a magician, you'll have to do this slowly and methodically. If you are a card player, or an excellent magician like Will Houstoun, you can do it almost instantly as you can see in the video!

If you switch your piles – the bottom half becomes the first pile and the top half the second pile – and then interleave the piles in the same way, you get the other type of perfect shuffle, called an *in-shuffle*.

**An out-shuffle in action...**

Suppose your pack consisted of the following 12 cards in this order, top to bottom:

Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen

You split the pack exactly in half:

A, 2, 3, 4, 5, 6

in the first pile, and

7, 8, 9, 10, J, Q

in the second pile.

Then an out-shuffle would reorder the cards in this way:

A, 7, 2, 8, 3, 9, 4, 10, 5, J, 6, Q

The top card, the Ace, and the bottom card, the Queen, of the original pack are fixed as the top and bottom card of the shuffled pack after an out-shuffle.

**...and an in-shuffle in action**

This time we swap the piles so the bottom half of the original pack is in the first pile:

7, 8, 9, 10, J, Q

and the top half of the pack is in the second pile:

A, 2, 3, 4, 5, 6.

Then an in-shuffle would reorder the cards in this way:

7, A, 8, 2, 9, 3, 10, 4, J, 5, Q, 6

### What could a magician do with a perfect shuffle?

To see a perfect shuffle in action, we were lucky enough to speak with Will Houstoun, a professional conjuror and the Magician in Residence at the Imperial College London and Royal College of Music Centre for Performance Science. As you'd expect, Houstoun has amazing physical control over the cards as you can see from the video. He can even do a variation of a perfect shuffle where he perfectly interleaves the cards two at a time, rather than one at a time. His control of the cards is incredible!

"Magicians are very interested in any way that you can make something impossible seem to happen," said Houstoun. "And knowing what is likely to happen to a pack of cards when it gets mixed up is part of that." Imagine if you wanted to begin with the cards in a particular order but you wanted people to think that the pack had been thoroughly shuffled. "Not that a magician would ever do such a thing!" Houstoun assured us.

"If you do eight perfect shuffles in a row [of a standard 52 card pack], the out-shuffles where you keep the top and bottom cards the same, then the deck goes back to the original order after eight repetitions of those out-shuffles. Admittedly it would take quite a long time, but if you wanted somebody to think that the deck was well mixed at the beginning of a trick, you could give it eight of these shuffles. [Everyone else] would then be 100% certain that the cards were well mixed, as they'd seen you mix them quite a lot, but in fact you would have your order ready to go." (You can see a mathematical proof of why this works, at the end of this article.)

### What could a magician do with an imperfect shuffle?

Our favoured method for an imperfect shuffle!

An *imperfect shuffle* is really what we have in mind when we think of a normal, fair, shuffle. "An imperfect shuffle is the best shuffle possible, as a shuffle's real purpose it to mix up the cards in random fashion," says Houstoun. To do an imperfect shuffle you might split the pack into roughly half and half, and then alternate the cards from the two halves in a more random fashion – with clumps of two or three cards alternating, as well as the occasional single card too. That randomness in how the cards interweave from the two halves is the thing that makes it a fair shuffle.

Imperfect shuffles are interesting to mathematicians too. "Persi Diaconis, who's a statistician as well as a very good magician, did work on the optimum number of shuffles to mix a pack of cards randomly", says Houstoun. Diaconis developed a procedure where you would undercut about a third of the pack (so a third of the pack gets cut from the bottom of the pack and placed on the top), then split the cards approximately in half, and then you give them an imperfect shuffle as described above. "If you repeat this procedure seven times that gives you the best balance between the number of shuffles performed and the impact that has on destroying the orders that could be located in the pack at the end of the process."

This mathematical understanding is useful in practice in places like casinos, where the amount of money they make relies on the randomness they expect to be found in a shuffled pack of cards: "The fairer the shuffle, the better it is for the casino, because they will be able to take advantage of their mathematical edge in the game's construction. That means they’ll win more than the player does." However, everytime the dealer is shuffling the cards, people are not playing cards or laying bets, so the casino has to decide on a process for shuffling that balances the randomness with the amount of bets that they can get out of customers.

### Perfect magic

The essence of an imperfect shuffle is that you don't want to end up with any particular, predictable order in the shuffled pack of cards. When we try to think of a special ordering of a pack of cards, we might think of one where the cards are in face value order, grouped in their suits, as they usually are with a new deck of cards. But one of Houstoun's most amazing card tricks plays with this idea of what orders we should think of as important.

After Houstoun and his audience have totally mixed up the pack of cards, we're not surprised to see a totally random looking order in the shuffled pack of cards. And the randomness of this order is emphasised by the huge surprise at the end of the trick.

Although Houstoun obviously couldn't divulge the secret behind the magic of the trick, he could tell us what motivated him to develop the trick: "I was thinking about the question of order, and why one thinks some orders are very important and some are not. A mixed up deck of cards, for example, is instantly dismissed. A pack of cards in new deck order is something people think is important. I thought it would be fun to do a trick that explores how an order that is seemingly unimportant is actually precise and is interesting in its own particular way."

We may have started out learning how to shuffle perfection, but actually it's imperfection that we really want whether we are playing cards at home against a friend, or betting against the house at a casino. As you'll see below, as well as magic there is a great deal of maths hidden within a card shuffle – something you can find out more about in the next article, *The mathematics of shuffling*.

### Show me the maths! Why eight out-shuffles is the same as none...

We were intrigued when Houstoun told us that doing eight out-shuffles of a standard 52 card pack returned you to the order of your original pack! There are various ways you can mathematically prove this, but the way we found most straightforward was explained by mathematician and magician Tori Noquez.

What we are interested in here is the order of the cards in the original pack, so we're going to forget about the value and suit of the card, and instead label all the cards with their original position in the pack. And, because it makes the maths easier, we're going to start by labelling the top card with a 0, the second card with a 1, and so on. So assuming we have a standard 52 card pack (the maths works for any even-number-sized pack) we'll label the cards:

0, 1, 2, 3, ..., 49, 50, 51

where 0 was the top card of the original pack, and 51 the bottom card.

An out-shuffle splits the cards into two halves, the top half in the first pile (0, 1, ..., 25) and the bottom half in the second pile (26, 27,..., 51), and interleaves them to give the following order:

0, 26, 1, 27, 2, ..., 24, 50, 25, 51.

Label = position in original pack |
Position in shuffled pack |
---|---|

0 | 0 |

1 | 2 |

2 | 4 |

... | ... |

25 | 50 |

26 | 1 |

... | ... |

50 | 49 |

51 | 51 |

The top card, with the label 0, remains at the top, position 0 in the shuffled pack. The bottom card with the label 51, remains at the bottom, position 51 in the shuffled pack. So we are really only interested in what happens for the rest of the cards, labelled 1 to 50, during an out-shuffle.

The cards in the first pile, the top half of the pack labelled with , are moved to the position in the shuffled pack. The card labelled 1 is moved to position 2 in the shuffled pack. The card labelled 2 is moved to position 4 in the shuffled pack. All the way to the card labelled 25, which is moved to position 50.

The cards in the second pile, the bottom half of the pack labelled with , are moved to the position in the new pack. The card labelled 26 is moved to position 1 ()in the shuffled pack. All the way to the card labelled 50 which is moved to position 49 () in the shuffled pack.

Using modular arithmetic (see here for a quick introduction to modular arithmetic) you can describe what happens to all the cards labelled 1 to 50 in the pack with just one rule: a card with label is moved to the position in the shuffled pack.

So for a card labelled where :

one out-shuffle takes to ;

two out-shuffles takes to ;

and so on. In general, out-shuffles takes the card labelled to position . To return to the original order of the pack, we are looking for the number of out-shuffles that returns the card labelled to its original position, that is:

So we are looking for the number that gives us

The first eight powers of two are:

1 | 2 | 2 |

2 | 4 | 4 |

3 | 8 | 8 |

4 | 16 | 16 |

5 | 32 | 32 |

6 | 64 | 13 |

7 | 128 | 26 |

8 | 256 | 1 |

Therefore eight out-shuffles gives us back the original pack order, and this is the smallest number of out-shuffles that can do that.

The same mathematics works for any size pack, (where is assumed to be even so you can split the pack exactly in half). To return the original pack order, you are looking for a number such that

*You can find our more in the next article, The mathematics of shuffling*

### About this article

This article is based on a talk that was part of the *Groups, representations and applications* programme at the Isaac Newton Institute. You can find out more about the maths behind this programme here.

Will Houstoun

Will Houstoun is an international award-winning magician and instructor, with a PhD in the history of magic education. He specialises in consultancy for media and advertising as well as instruction on both the technical and historic aspects of magic. Will is the Magician in Residence at the Imperial College London/Royal College of Music Centre for Performance Science.

Rachel Thomas is Editor of *Plus*.

*This article is part of our collaboration with the Isaac Newton Institute for Mathematical Sciences (INI), an international research centre and our neighbour here on the University of Cambridge's maths campus. INI attracts leading mathematical scientists from all over the world, and is open to all. Visit www.newton.ac.uk to find out more.*