### On Perfect Shuffles

There is a fun fact known to card players -- if you take a pristine, ordered deck of cards and perform the usual ripple shuffle on it 8 times, you will end up with the original, unshuffled deck. Some players even frown upon dealers who do the ripple shuffle too many times because of worries that the deck will somehow "lose randomness" that way. In fact, the "eight perfect shuffles" anecdote is just a mathematical curiosity. Practice isn't as compelling as the theory.

First, let me define what most people mean by the term "a perfect shuffle". You take a deck of 52 different cards and put it on the table in front of you. You then pick up the top half (26 cards) with your right hand and move those cards to the right side. You pick up the remaining 26 cards with your left hand. While holding the two halves of the deck in your two hands, you let cards drop from the bottoms of the two half-decks into the middle, creating a new deck. First, you drop one card from your left hand, then a card from your right hand, then a card from the left, and so on until all 52 cards are in the new deck in the middle, forming an alternating zipper-like pattern. You then straighten the edges of the new deck and repeat the procedure (take the top half into the right hand, etc.)

If you do this eight times, you will end up with the deck in the original order; that's true. However, it is very important that the first card you drop fall from your left hand (the bottom half). In fact, that card will never move from the bottom. It is always going to be the first one to fall and the only one to touch the table. Similarly, the top card will always remain on top. The "shuffle" isn't really doing its job here, is it?

We can fix that. Instead of starting the zipper by dropping a card from the left hand, let's start with the right one. That way, the bottom card will at least move one position up in the deck, and the top card will move one position down. Suddenly, the rule of eight does not apply anymore. It will now take 52 shuffles to get back to the original order of the deck.

Don't try this; you'll mess it up. Write a computer program to simulate this shuffle instead. If you have ever actually tried to perform the perfect shuffle, you probably know how difficult it is to get it exactly right. If you misplace even a single card, the whole trick is ruined.

Let's call the original perfect shuffle

Fancier combinations like (L, L, R, L, L, R, L, L, R, ...) and (L, R, R, L, R, R, L, R, R, ...) produce shorter periods of 80 and 160, respectively.

Now, what happens if you get really good at the perfect shuffle, but you have trouble controlling whether you do the left-handed or the right-handed version on each try? Let's say you pick the version at random. It turns out that you will

I'm not sure what the moral of the story is, except that -- if you are sitting at the table, ripple-shuffling a deck of cards, and you stop to look at the order of the cards, chances are that the cards will not be perfectly ordered... unless you are a sleight-of-hand expert.

Captain Obvious would be proud.

First, let me define what most people mean by the term "a perfect shuffle". You take a deck of 52 different cards and put it on the table in front of you. You then pick up the top half (26 cards) with your right hand and move those cards to the right side. You pick up the remaining 26 cards with your left hand. While holding the two halves of the deck in your two hands, you let cards drop from the bottoms of the two half-decks into the middle, creating a new deck. First, you drop one card from your left hand, then a card from your right hand, then a card from the left, and so on until all 52 cards are in the new deck in the middle, forming an alternating zipper-like pattern. You then straighten the edges of the new deck and repeat the procedure (take the top half into the right hand, etc.)

If you do this eight times, you will end up with the deck in the original order; that's true. However, it is very important that the first card you drop fall from your left hand (the bottom half). In fact, that card will never move from the bottom. It is always going to be the first one to fall and the only one to touch the table. Similarly, the top card will always remain on top. The "shuffle" isn't really doing its job here, is it?

We can fix that. Instead of starting the zipper by dropping a card from the left hand, let's start with the right one. That way, the bottom card will at least move one position up in the deck, and the top card will move one position down. Suddenly, the rule of eight does not apply anymore. It will now take 52 shuffles to get back to the original order of the deck.

Don't try this; you'll mess it up. Write a computer program to simulate this shuffle instead. If you have ever actually tried to perform the perfect shuffle, you probably know how difficult it is to get it exactly right. If you misplace even a single card, the whole trick is ruined.

Let's call the original perfect shuffle

*left-handed*(because we start dropping cards with the left hand), and the new, arguably better shuffle*right-handed*. We could say that the left-handed perfect shuffle has a*period*of 8, while the right-handed version has a*period*of 52. Let's see what would happen if we alternated between the left-handed and the right-handed shuffles like this: L, R, L, R, L, R, ... It turns out, that we get a period of 504. We get the same period by using the pattern R, L, R, L, R, L, ...Fancier combinations like (L, L, R, L, L, R, L, L, R, ...) and (L, R, R, L, R, R, L, R, R, ...) produce shorter periods of 80 and 160, respectively.

Now, what happens if you get really good at the perfect shuffle, but you have trouble controlling whether you do the left-handed or the right-handed version on each try? Let's say you pick the version at random. It turns out that you will

*never*get back to the original ordering (well, at least not in your lifetime). Five or ten shuffles in, the deck's ordering will look pretty random. The chances of getting back to the sorted deck in fewer than 1000 shuffles are smaller than one in 200, and once you have performed a few shuffles already, the chances drop exponentially.I'm not sure what the moral of the story is, except that -- if you are sitting at the table, ripple-shuffling a deck of cards, and you stop to look at the order of the cards, chances are that the cards will not be perfectly ordered... unless you are a sleight-of-hand expert.

Captain Obvious would be proud.