The 100 prisoners problem
One hundred prisoners and 100 boxes are each numbered 1–100. The prisoners’ numbers are placed randomly in the boxes, one per box. Each prisoner may open 50 boxes, alone. They can agree on a strategy beforehand, but cannot communicate afterwards or leave the boxes changed. Everyone goes free only if everyone finds their own number. Can they give themselves a chance of more than 30%?
A strategy and why it works
Start with the box bearing your number, then open the box named by the number inside, and keep following. The arrangement is a permutation, so it splits into cycles. Everyone succeeds exactly when no cycle is longer than 50.
For k > 50, there can be at most one k-cycle. Choose its k numbers, arrange them in a cycle, then arrange the rest. This counts 100! / k of the 100! possible permutations, so the probability of such a cycle is 1 / k. Two cycles longer than 50 cannot coexist, so the failure probabilities simply add:
P(success) = 1 − (1/51 + 1/52 + ⋯ + 1/100) ≈ 31.18%.
Each prisoner still has a one-half chance of finding their number. The trick is to make their successes depend on one another. Independent guesses would give the group only a 2−100 chance.
Further reading: Peter Winkler’s explanation (PDF).