applets.

Shuffle Maths

← All apps

About Shuffle Maths

Four tabs about counting arrangements. 52! shuffles a deck and shows how many orders a deck can be in. 7 SHUFFLES riffles a deck one shuffle at a time, colouring each card by where it started, and charts how far from random the deck still is. CALCULATOR works out n!, permutations, combinations and codes with repeats, in full however big, with everyday examples. BIRTHDAYS fills a room with random birthdays. Key: S shuffles (or riffles) on the first two tabs.

THE STORY

The exclamation mark for a factorial, as in 5! = 5 × 4 × 3 × 2 × 1 = 120, was introduced by the French mathematician Christian Kramp in 1808. A deck of 52 cards can be put in 52! different orders, a 68-digit number, about 8.07 × 1067. That is so many that a well-shuffled deck is almost certainly in an order no deck has ever been in before.

But how much shuffling is "well shuffled"? In 1992 Dave Bayer and Persi Diaconis answered this in a paper called "Trailing the Dovetail Shuffle to its Lair". Using the Gilbert–Shannon–Reeds model of a riffle shuffle, they worked out exactly how far a 52-card deck is from random after each riffle. The deck stays far from random for the first five, then the distance falls sharply: about seven riffles are needed before it is reasonably well mixed.

The birthday problem asks how many people need to be in a room for an even chance that two of them share a birthday. The answer, 23, surprises most people, because what matters is the number of pairs: 23 people make 253 pairs.

HOW IT WORKS

Shuffling. SHUFFLE uses your browser's secure random numbers and the Fisher–Yates method, so every one of the 52! orders is equally likely (the riffle you see is just for show). The page also works out this order's place in the list of all 52! orders.

How big is 52!? The working, from these assumptions: a year of 365.25 days is 31,557,600 seconds, and the universe is about 13.8 billion years old, so about 4.35 × 1017 seconds. Dealing out every order at a billion a second takes 52! ÷ 109 ≈ 8.07 × 1058 seconds, about 2.6 × 1051 years, which is about 1.9 × 1041 times the age of the universe. If 8 billion people had each shuffled a deck once a second for the whole age of the universe, that would be about 3.5 × 1027 shuffles, a share of about 4 × 10−41 of all orders. And by the birthday-problem reckoning, the chance that any two of those shuffles ever matched is less than (number of shuffles)² ÷ (2 × 52!), about 7.5 × 10−14.

Riffles. In the Gilbert–Shannon–Reeds model you cut the deck where tossing a coin for each card says, so usually near the middle, then drop cards from the two packets, each time from a packet with a chance in proportion to how many cards it holds. One riffle leaves the deck as at most two "rising sequences" (cards 1, 2, 3 ... in their old order), k riffles at most 2k. Bayer and Diaconis showed that after k riffles of n cards, an order with r rising sequences has chance C(2k + n − r, n) ÷ 2kn. Adding up the gap to a perfect shuffle over every order (the "total variation distance") gives the chart; it is computed here exactly with whole numbers: 0.924 after 5 riffles, 0.614 after 6, 0.334 after 7, 0.167 after 8.

Counting. n! = n × (n − 1) × ... × 1 orders of n things. nPr = n! ÷ (n − r)! ordered choices of r things from n. nCr = nPr ÷ r! choices where order doesn't matter. Codes with repeats: nr, so 104 = 10,000 four-digit PINs from 0000 to 9999. A Rubik's cube has 8! × 37 × 12! × 211 ÷ 2 = 43,252,003,274,489,856,000 positions: the corners can be placed 8! ways and twisted 37 ways (the last twist is forced), the edges placed 12! ways and flipped 211 ways (the last flip is forced), and only half of those can be reached by turning.

Birthdays. The chance that m people all have different birthdays is 365 × 364 × ... × (365 − m + 1) ÷ 365m, worked out here exactly. This assumes every day is equally likely and ignores 29 February.

FURTHER WATCHING AND READING

52! IN FULL

52!

= 52 × 51 × 50 × ... × 2 × 1, the number of orders 52 cards can be in: 68 digits.

SHUFFLE THE DECK

HOW BIG IS THAT?

    Show the working