On this page
What is the 100 prisoners problem?
The puzzle was first posed, in a version with coloured slips of paper, by Anna Gál and Peter Bro Miltersen in a 2003 paper at the ICALP conference on automata, languages and programming. The prisoner version is set out in the 100 prisoners problem article on Wikipedia: 100 prisoners are numbered 1 to 100, and their numbers are shuffled at random into 100 numbered boxes in a room. One at a time, each prisoner enters, opens at most 50 boxes and leaves the room exactly as they found it. They cannot talk once the first prisoner goes in, but they may agree a plan beforehand. If every prisoner finds their own number, all go free; if even one fails, all fail.
A prisoner who opens 50 boxes at random has a 50% chance of success. If all 100 guess independently, the chance that every one succeeds is (1/2)^100, which Wikipedia gives as about 0.0000000000000000000000000000008.
How does the cycle strategy work?
Each prisoner follows one rule:
Open the box with your own number on it.
If the slip inside shows k, open box k next.
Keep going until you find your own number or have opened 50 boxes.
Draw an arrow from each box to the number inside it. Every box has one arrow out and one in, so the arrows join into closed loops, called cycles. The slip with your number is the one pointing back to your box, so following the arrows from your box always reaches it. The only question is whether your loop is short enough. If this is new, see cycle notation in the symmetric group.
Take 8 prisoners who may each open 4 boxes, as in the diagram. Box 1 holds 5, box 5 holds 3 and box 3 holds 1. Box 2 holds 7, box 7 holds 8, box 8 holds 4, box 4 holds 6 and box 6 holds 2.
Prisoner 1 opens box 1 (finds 5), box 5 (finds 3), box 3 (finds 1). Found in three boxes.
Prisoner 2 opens box 2 (finds 7), box 7 (finds 8), box 8 (finds 4), box 4 (finds 6). Four boxes used, and 2 is still hidden in box 6.
Everyone on the loop of length 3 succeeds; everyone on the loop of length 5 fails.
Why is the success probability about 31%?
The strategy fails only if the shuffle has a cycle longer than 50, and there can be at most one such cycle, since two would need more than 100 boxes. For a fixed length k above 50, count the shuffles with a cycle of length k: choose its k numbers in C(100, k) ways, arrange them in a loop in (k − 1)! ways, and arrange the other 100 − k numbers in (100 − k)! ways. The product is 100!/k, so the probability is exactly 1/k.
Adding these from k = 51 to k = 100 gives the failure probability, H₁₀₀ − H₅₀ ≈ 0.688, where Hₙ = 1 + 1/2 + … + 1/n is the n-th harmonic number. The 100 prisoners problem article gives the success probability as 1 − (H₁₀₀ − H₅₀) ≈ 0.31183. As the number of prisoners grows, the same article shows this tends to 1 − ln 2 ≈ 0.30685, so the strategy works more than 30% of the time however many prisoners there are. For counting permutations by cycles, see Stirling numbers of the first kind.
Is the cycle strategy the best possible?
Yes. In 2006, Eugene Curtin and Max Warshauer proved in The Mathematical Intelligencer that no strategy gives the prisoners a higher chance of going free. Their proof, as the Wikipedia article explains, compares the puzzle with a version where every prisoner watches every box opened: there every strategy wins equally often, so none can beat cycle-following.
How can you check this yourself?
You need the cards ace to 8 from one suit, with the ace standing for 1.
Shuffle them and lay them face down in a row. Positions 1 to 8 are the boxes.
For each prisoner 1 to 8, follow the rule, turning over at most 4 cards and turning them back afterwards.
Write the shuffle as cycles: the round fails exactly when a cycle is longer than 4.
Predict the result first. With the same 1/k rule from the Wikipedia article, 8 prisoners win with probability 1 − (1/5 + 1/6 + 1/7 + 1/8) = 307/840, about 36.5%, against (1/2)^8 = 1/256 for guessing.
Play 20 rounds. You should win roughly 7 of them.
If permutations, cycles or harmonic numbers feel shaky, the Fermi Concept Library gives every concept in mathematics its own lesson. To practise counting problems like the 1/k argument, the Fermi Problem Library has worked problems with a step-by-step solver that explains the reasoning rather than printing an answer.
Next, try the secretary problem and its 1/e rule, another puzzle where a simple rule does surprisingly well.



