The 27-Card Trick
You name a number from 1 to 27 and silently pick one of 27 cards. Three times, you say only which column your card is in. When the cards are counted, yours is at exactly your number.
Watch the lectureLecture 46 · The 27-card trick: choose the destination
Try it
Choose a destination, then think of any card. All I ever learn is which column it is in.
Why it works
Keep track of one number: how many cards lie above your card. Call it p. With 27 cards, p runs from 0 (the top card) to 26 (the bottom card). Destination 17 means 16 cards above.
Dealing left to right across rows sends the card with p cards above it to row ⌊p/3⌋ of column p mod 3. For example, 22 = 3 × 7 + 1, so that card lands in row 7 of column 1, counting both from zero: the middle column. So your column report tells me the remainder, and nothing else.
When I gather, each column keeps its row order, so inside its column your card has ⌊p/3⌋ cards above it. Putting that column on top, in the middle or at the bottom adds 0, 9 or 18 more. Writing k = 0, 1, 2 for those three places, the new count is
p′ = 9k + ⌊p/3⌋.
Now write p in base three, with three digits: nines, threes, units. Dividing by three and dropping the remainder throws away the units digit and slides the other two one place to the right. Adding 9k writes k into the empty nines place. So one round turns the digits a₂ a₁ a₀ into k₁ a₂ a₁. After three rounds they are k₃ k₂ k₁, and none of the starting digits is left.
To send the card to destination T, write T − 1 in base three and use its digits from the units end: 17 − 1 = 16 = 121 in base three, so the gathers go middle, bottom, middle. The first gather becomes the units digit, because each later round pushes it one place further right.
Each gather throws away one base-three digit of where your card was and writes one digit of where it should go. After three gathers, only my digits remain.
Challenge
Be the performer. Choose the three gathers for a destination, then run every one of the 27 possible cards through your code. Or read a code and predict where the card lands.
Perform it yourself
Set-up
- Any 27 different cards. The spectator may shuffle them freely. Keep every card face up throughout.
- Ask for a destination from 1 to 27 and write it down before the card is chosen.
- Work out the three gathers: subtract one, write the result in base three, and read the digits from the right (0 = top, 1 = middle, 2 = bottom). Or read them from the table below. It is fine to consult it openly while you learn.
Performance
- Deal the face-up packet left to right across rows, nine rows of three. Deal all 27 cards in complete rows: exactly nine in each column.
- The spectator silently picks a card and tells you only its column: left, middle or right.
- Gather each column by starting with its bottom card and placing each higher card on top. The top-row card ends on top. Never turn a column over; that would reverse its order.
- Decide the final top-to-bottom order of the three columns first: the reported column goes where this round’s digit says, and the other two keep their left-to-right order around it. Then assemble it from the bottom up.
- Deal again and repeat for the second and third digits. The spectator must follow the same card all three times. If they lose it or change their mind, start a fresh three-round run.
- Ask the spectator to name their card. Count down from the top, saying “one” for the first card, and stop at the destination.
Count the reveal from one, but calculate with “cards above”, from zero. Subtracting one at the start and adding it back at the end keeps the two in step. An off-by-one slip here is bookkeeping, not a failure of the method.
All 27 destinations and their gathers
T = top, M = middle, B = bottom, in the order of rounds 1, 2, 3.
Going deeper
The old 21-card trick is a different machine
The classic version deals 21 cards into three columns of seven and always gathers the chosen column in the middle. Now a column holds seven cards, so the update is p′ = 7k + ⌊p/3⌋, with 7 in place of 9.
With k = 1 every time, the possible numbers of cards above shrink from 0–20 to 7–13, then 9–11, then just 10. The card finishes eleventh. That is a direct proof, but it is not the base-three argument: 21 is not a power of three, so the destination table above does not carry over to 21 cards.
27 → 9 → 3 → 1: information is not the whole story
Three answers with three options each can tell apart 3 × 3 × 3 = 27 possibilities, which is why three rounds are enough. But counting possible messages does not tell you how to gather the cards. A careless gather can ask the same three questions and still scatter the card.
The position update is the constructive part, and the digit shift proves that it works for every starting card. The procedure has to adapt: different column answers move different packets. No single fixed shuffle could send all 27 starting positions to one place.
When the handling goes wrong
If a column is gathered upside down, your card’s place inside it becomes 8 − ⌊p/3⌋ instead of ⌊p/3⌋. That is a different update, and the table above no longer applies. If the spectator reports a column for a different card, the run follows that other card from then on. In both cases, look for the first round where the real packet stops matching the formula. That round is where the mistake happened.
Sources
Matt Parker’s choose-your-position version for Numberphile, “Beautiful Card Trick”, motivates this episode. The all-face-up, row-order-preserving handling and the ternary lookup are checked adaptations for this course. For the classic version see Numberphile’s 21-card trick. The three-pile trick is centuries old, and its general analysis is often called Gergonne’s pile problem.
Course episodes 46 (performance) and 47 (a card position written in base three).