◍ Hidden Spheres · exhibit nº 24

The Hundred Prisoners

a hundred boxes, fifty looks each, and the trick that turns one in a million million million million million into nearly one in three

A hundred prisoners are numbered 1 to 100. In a room stand a hundred closed boxes, and in each box a slip with one of the numbers, every number once, in an order nobody knows. One at a time each prisoner walks in, may open fifty boxes, and must find the slip with their own number. They leave everything as it was and cannot speak to the others afterwards. If every single prisoner finds their number, all go free. If even one fails, nobody does. They may agree on a plan beforehand. What plan?

follow the slips: open your own box, then the box it names

For the curious kid.

If everyone just guesses, each prisoner has a one in two chance, and you need a hundred one-in-two chances to come up right all at once. That is a coin landing heads a hundred times in a row. Try it with Guess at random: about fifty of them find their number every round, and all hundred never do, not in your lifetime, not in the lifetime of the universe. The chance is one in a million million million million million.

Here is the plan. Open the box with your own number on it. Inside is a slip with some number; go open that box. Keep following the slips. You are walking a loop, and your own number is the last slip on it, the one that points back to where you started. If your loop has fifty boxes or fewer, you will find your number in time. If it is longer, you won't, and neither will anyone else on that loop. The picture on the left shows the boxes drawn as the loops they make. Press Send the next prisoner and watch one walk their loop; press Send them all and see the whole hundred live or die by the longest loop in the room.

So the question becomes: how often does a shuffle of a hundred things have no loop longer than fifty? Nearly a third of the time. The chart on the right counts the longest loop in every round you play and draws the exact answer in gold over your count. The shaded part, fifty boxes and under, is where everybody goes home.

Deeper.

The boxes and slips are a permutation of 100 things, and every permutation is a set of disjoint cycles. The loop strategy turns a hundred independent one-in-two gambles into one question about the permutation's cycle structure, and that is the whole trick: the prisoners stop being independent, so their failures pile up on the same rounds instead of spreading out across all of them. A loop longer than 50 can occur at most once, and the probability that a random permutation of n has a cycle of length exactly k, for k above n/2, is exactly 1/k. So the chance of ruin is the sum of 1/k from 51 to 100, which is H₁₀₀ − H₅₀ in harmonic numbers, and survival is 1 − (H₁₀₀ − H₅₀) = 0.31183. As n grows the sum tends to ln 2 and survival to 1 − ln 2 = 0.30685, from above, the gap closing like 1/(2n). The gold curve in the chart is computed from the recurrence p(n, k) = (1/n) Σⱼ p(n − j, k) over j = 1..k, the probability that every cycle of a random permutation of n has length at most k; the page checks it against the harmonic formula and against all 40,320 permutations of eight boxes before it draws a thing.

The puzzle was posed by Peter Bro Miltersen in 2003 and the loop strategy was found by Sven Skyum; Eugene Curtin and Max Warshauer proved in 2006 that no strategy does better. One honest note: the ruin probability above is for a shuffle chosen fairly. A warden who knows the plan can fill the boxes so that they form one loop of a hundred and the prisoners die every time. The prisoners have an answer to that too, which this room keeps for those who look.

Your fate is not in your box. It is in the shape of the whole room, and the shape is the same for everyone.