You are on page 1of 13

Perfect Shuffles: A Shortest Sequence to Move a Card

Katie Glacey
Masters Expository Paper

In partial fulfillment of the MAT Degree


Department of Mathematics
University of Nebraska-Lincoln
July, 2011
A deck of cards can be found in many households in the world. The earliest
reference to playing cards can be dated to the year 1377. The ubiquitous nature of
cards leads some to take the card shuffling for granted.
The fascination with card shuffling is not a recent occurrence but has been
studied for many years. The study of card shuffling has enveloped the minds of
magicians, mathematicians, and even a rancher. Magician and mathematician Persi
Diaconis wanted to determine the perfect number of shuffles for a deck of cards. He
determined that seven shuffles was the perfect amount. Mathematical writer Martin
Gardner pondered an efficient algorithm to bring any card to the top of a deck
through a combination of shuffles. Even a Nebraska rancher was enthralled with the
idea of card shuffling. Rancher Fred Black practiced shuffling on horseback and
gained recognition by Ripleys Believe It or Not for his ability to deal four Bridge
hands, collect them, shuffle the deck, cut and shift the deck, and deal identical hands
to the same players in less than one minute.
When one shuffles cards the goal is to randomize the cards, but in fact the
cards permute in a systematic fashion. The randomizing of a deck of cards can be
done improperly or precisely, and that knowledge can be used to either the
shufflers disadvantage or advantage. A card dealer in a casino would receive the
disadvantage of an improper card shuffle, because a very astute gambler can use the
knowledge to his or her advantage. A magician can take advantage of a card shuffle
done is a precise manner. The magician is actually employing mathematics to
amaze the audience.

The Cards and the Shuffles


This examination of card shuffling employs a deck of 2n cards. The positions
of the cards are labeled 0 through 2n-1. Position 0 is the top position in the deck.
The bulk of the analysis of shuffling revolves around two very precise variations of a
shuffle referred to as the riffle shuffle: the perfect in-shuffle and the perfect out-
shuffle. In the perfect in-shuffle, a deck is cut in half into stacks of n cards and
interlaced with each other so the original top card moves into the second position of
the shuffled pile. In the perfect out-shuffle, the two stacks of n cards are interlaced
so that the original top card of the deck remains in the top position after shuffling.

The Position Functions


To begin this investigation, I observed the nature of the cards when shuffling,
to develop position functions to help determine the position of a card originally in x
position to describe its position after one perfect in-shuffle and one perfect out-
shuffle.

The Perfect In-Shuffle

Given a stack of cards with 2n = 12, I observed and noted the shift in positions as
seen below.

Position 0 1 2 3 4 5 6 7 8 9 10 11
Card A B C D E F G H I J K L

After one perfect in-shuffle


Position 0 1 2 3 4 5 6 7 8 9 10 11
Card G A H B I C J D K E L F
Number +6 -1 +5 -2 +4 -3 +3 -4 +2 -5 +1 -6
of
Positions
Moved

I noticed that after one in-shuffle that the movement of the cards created a mirror
image of movement. After n cards the pattern of movement begins to reflect but
with opposite signs. To create a function to describe the movement in position, I
had to consider two separate cases based on where the card was originally in the
deck.
Case One: x < n

When x < n, a cards position will move down 2x + 1 positions after one
perfect in-shuffle.

Observe:

Position 0 1 2 3 4 5 6 7 8 9 10 11
Card A B C D E F G H I J K L

After one perfect in-shuffle


Position 0 1 2 3 4 5 6 7 8 9 10 11
Card G A H B I C J D K E L F

After one perfect in-shuffle, a card originally in the second position will be in the
fifth position.

The variables used in the function to describe this movement are:


x = cards position
f(x) = cards new position after one perfect shuffle

The function to describe this movement is: f(x) = 2x + 1 when x < n.

Case Two: n < x < 2n-1

When n < x < 2n-1, a cards position moves up the difference between 2x and
2n in the shuffled pile after one perfect in-shuffle.
Observe:

Position 0 1 2 3 4 5 6 7 8 9 10 11
Card A B C D E F G H I J K L

After one perfect in-shuffle


Position 0 1 2 3 4 5 6 7 8 9 10 11
Card G A H B I C J D K E L F

After one perfect in-shuffle, a card originally in the seventh position will be in the
second position, which is a movement of five places from its original position.

The variables used in the function to describe this movement are:


x = cards position
2n = the total number of cards in a deck
f(x) = cards new position after one perfect shuffle

The function to describe this movement is: f(x) = 2x 2n when n < x < 2n-1.

The Perfect Out-Shuffle

Given a stack of cards with 2n = 12, I observed and noted the shift in positions as
seen below.

Position 0 1 2 3 4 5 6 7 8 9 10 11
Card A B C D E F G H I J K L
After one perfect out-shuffle
Position 0 1 2 3 4 5 6 7 8 9 10 11
Card A G B H C I D J E K F L
Number 0 +5 -1 +4 -2 +3 -3 +2 -4 +1 -5 0
of
Positions
Moved

I noticed that after one out-shuffle that the movement of the cards created a mirror
image of movement. After n cards the pattern of movement begins to reflect but
with opposite signs. Also, the positions of the first and last card do not change after
one perfect out-shuffle. To create a function to describe the movement in position, I
had to consider two separate cases based on where the card was originally in the
deck.

Case One: x < n

When x < n a cards position will move down 2x positions after one perfect
out-shuffle.

Observe:

Position 0 1 2 3 4 5 6 7 8 9 10 11
Card A B C D E F G H I J K L

After one perfect out-shuffle


Position 0 1 2 3 4 5 6 7 8 9 10 11
Card A G B H C I D J E K F L
After one perfect out-shuffle, a card originally in the second position will be in the
fourth position.

The variables used in the function to describe this movement are:


x = cards position
f(x) = cards new position after one perfect shuffle

The function to describe this movement is: f(x) = 2x when x < n.

Case Two: n < x < 2n-1

When n < x < 2n-1, a cards position moves up the difference between 2x and
2n+1 in the shuffled pile after one perfect out-shuffle.

Observe:

Position 0 1 2 3 4 5 6 7 8 9 10 11
Card A B C D E F G H I J K L

After one perfect out-shuffle


Position 0 1 2 3 4 5 6 7 8 9 10 11
Card A G B H C I D J E K F L

After one perfect out-shuffle, a card originally in the seventh position will be in the
third position, which is a movement of four places from its original position.

The variables used in the function to describe this movement are:


x = cards position
2n = the total number of cards in a deck
f(x) = cards new position after one perfect shuffle
The function to describe this movement is: f(x) = 2x 2n + 1 when n < x < 2n-1.

Shortest Possible Sequence

In the paper Moving Card i to Position j with Perfect Shuffles by Sarnath


Ramnath and Daniel Scully, the authors used the pictorial representation of trees to
present perfect shuffles. The trees create a visual path to follow to get a card from
one position to another. The authors used the following functions in base 2 to
create the trees.

They then let Dm(x) = 2x mod 2n and Em(x) = (2x + 1) mod 2n. Starting at position 0
they applied the functions branching out to create the following.
In this diagram in order to go from position 0 to position 4, the cards must be
shuffled by applying one Em followed by two Dms.

To streamline the process, the authors decided it was unnecessary to construct the
whole tree but only to construct the outermost path from a position i to a position j
since dealing with a standard 52 card deck would result in a giant tree. To construct
the outermost path the following is used:

(Dm(i), D 2m (i), . . . Dtm(i) and Em (i), E 2m (i),. . . E tm(i)) until j falls in the interval
[Dtm(i), Etm(i)]. (In Z2n , [a, b] = {a, a + 1. b} if a < b, and [a, b] = {a, a + 1. 2n - 1, 0, 1,... b
if b < a.)
Example
In the following example, I will illustrate moving a card from i to j using the
theorem and steps set forth by Ramnath and Scully. i = 10 and j = 33.

In the article the authors illustrated the theorem: Label the positions in a
deck of 2n cards 0 through 2n 1 consecutively with 0 representing the top position.
To determine the shortest possible sequence of perfect in and out shuffles that will
move a card in position i to position j, proceed as follows:

1. Calculate the sequences Dm(i), D2m(i), . . ., Dtm(i) and Em(i), E2m(i), . . ., Etm(i) until j
[Dtm(i), Etm(i)]

The number 33 falls between the interval [28, 35] in Z52. I had to apply the function
3 times to find the interval that contains j so t = 3.

2. Let s = (j Dtm (i))mod 2n and write s as a t-digit base two numeral s1s2. . . st.

s = (j Dtm (i))mod 2n = (33-28) mod 52 = 5 mod 52 = 5

This now needs to be written as a 3-digit base two numeral so it becomes 101.

3. Reading the digits s1 s2. . . . st from left to right, apply consecutively Dm to i if sk is


0 and Em if sk is 1.
So 101 becomes

Em Dm Em

4. Make the translation Dm = O if Dm is being applied to an integer in [0, n-1] and Dm = I


if applied to an integer in [n, 2n - 1]. Similarly, Em = I in [0, n - 1] and Em = O in [n, 2n -
1]. The resulting sequence of in and out shuffles (I's and O's) moves the card in position
i to position j in a minimum number of perfect shuffles.

Cards Position 10 21 42 33
Function Applied to Achieve Position Em Dm Em
Translation of Position and Applied Function In Out Out

So to move a card in the 10th position to the 33rd position in the least amount
of perfect shuffles, apply one perfect in-shuffle followed by two perfect out-shuffles.

A Classroom Activity
The activity of card shuffling can be brought into the classroom through the
study of modular arithmetic. I teach fifth and sixth grade, so this activity is geared
toward the intermediate level (grades 3 through 6) of elementary school.
The activity begins with an introduction of modular arithmetic through the
study of time on a clock.
1) Ask students what time it will be 3 hours after noon? 10 hours after
noon? 14 hours after noon? 28 hours after noon?
2) Ask student to explain how they were able to arrive at the various
answers.
3) Focus on the remainder and introduce the notation for modular
arithmetic.
Once the ideas of modular arithmetic and correct notation have been established,
shift to the everyday object of cards.
4) Explain the concept of perfect in-shuffle.
5) Distribute to the students 10 playing cards.
6) Students work and apply perfect in-shuffles to their 10-card deck of cards.
Students record the movement of the cards into chart.
7) Discuss results.
8) Wrap up with describing movement of cards in modular arithmetic form.
References

S. Ramnath and D. Scully, Moving Card I to Position j with Perfect Shuffles,


Mathematics Magazine, Volume 69, Number 5 (1996), pp. 361-365.

You might also like