One hundred people must each find their own number among 100 closed boxes, but each person may open only 50 of them, and the group wins only if all 100 succeed. Once the search begins, nobody can pass on any information. If everyone opens 50 boxes at random, all of them succeed with probability , less than one chance in . This page explains a plan in which each person follows the numbers from box to box, shows that it wins exactly when the random arrangement has no cycle longer than 50, and computes that chance, about 31.18 percent.
Key terms
100 prisoners problem
Definition The 100 prisoners problem is a probability puzzle with fixed rules. There are 100 people, numbered 1 to 100, and a room with 100 boxes, also numbered 1 to 100. Each box holds one slip of paper, the slips carry the numbers 1 to 100, and every number is in exactly one box. The slips are placed by a uniformly random permutation, so each of the possible arrangements is equally likely, and the arrangement does not depend on the group’s plan. Before the first person enters, the group may agree on a strategy, and after that its members cannot communicate in any way. The people enter the room one at a time. Each may open at most 50 boxes, one after another, choosing each box after seeing what the earlier ones held. Each person then leaves the room exactly as it was found, with every box closed, every slip in its own box and no marks left behind. The group wins only if every one of the 100 people opens the box that holds their own number. If each person opens 50 boxes chosen at random, independently of everyone else, the group wins with probability . With the cycle-following strategy described below, the group wins with probability
about 31.18 percent. This formula is exact for 100 people who may each open 50 boxes. The number that is often quoted is the limit of the same calculation for larger and larger groups in which each person may open half of the boxes, not the answer for 100 people.
In plain words Random searching is like 100 separate coin flips that must all come up heads. The cycle-following strategy leaves each person’s own chance at one half but links the outcomes, so that people succeed or fail in large groups, and in about 31 percent of arrangements everybody succeeds.
Example Under random searching, person 1 opens 50 of the 100 boxes, so the box with number 1 is among them with probability , whatever the arrangement. The choices are made independently, so the chance that all 100 people succeed is
Under cycle following each person also succeeds with probability exactly , yet the group wins with probability about , roughly times as often. A computer simulation of 200,000 uniformly random arrangements found a win in about 31.0 percent of them, close to the exact value.
Random permutation
Definition A permutation of the numbers 1 to is a rule that assigns to each number from 1 to a number from 1 to , in such a way that each number is assigned exactly once. In the puzzle, is the number on the slip in box . There are
permutations of numbers. A permutation is uniformly random when each of the permutations has the same probability . Then each box holds each number with probability , but the boxes are not independent of one another, because no number can appear in two boxes.
In plain words A uniformly random permutation is what you get by shuffling the 100 slips thoroughly and dropping one into each box. No arrangement is more likely than any other.
Example Three boxes can be filled in ways. Listing the numbers in boxes 1, 2 and 3 in that order, the arrangements are 123, 132, 213, 231, 312 and 321, each with probability . Box 2 holds the number 2 in two of them, 123 and 321, so with probability . If box 1 is known to hold 1, only 123 and 132 remain, and box 2 holds 2 with probability . Learning about one box changed the chances for another, which shows that the boxes are not independent.
Permutation cycle
Definition Let be a permutation of the numbers 1 to , and start at a number . Applying again and again gives the sequence , and since there are only numbers, some number must eventually repeat. The first number to repeat is itself, because never sends two different numbers to the same number. If the sequence first returns to after steps, the different numbers it visits form the cycle containing , and is the length of that cycle. Every number lies in exactly one cycle, so the cycles split the numbers 1 to into separate groups whose lengths add up to . A cycle is written in parentheses in the order it is followed, so means that 1 goes to 4, 4 goes to 2 and 2 goes back to 1. For any length with , a uniformly random permutation of numbers has a cycle of length with probability exactly . To count these permutations, choose the numbers of the cycle in ways, link them into a cycle in ways, and arrange the other numbers in any of ways. The factor appears because the chosen numbers can be listed in orders and each cycle appears times among them, once for each starting number. A permutation cannot have two cycles longer than , since together they would need more than numbers, so no permutation is counted twice, and the count is
Dividing by the equally likely permutations gives .
In plain words Start at any box, read its slip, go to the box with that number and keep going. Every box number is written on exactly one slip, so the path can never run into a loop partway along. It must come back to the box where it started, and the boxes it passes through form that box’s cycle.
Example Take six boxes holding 4, 1, 6, 2, 5 and 3, in that order, so box 1 holds 4, box 2 holds 1, box 3 holds 6, and so on. Starting at 1 gives 1, 4, 2 and then 1 again, so one cycle is . Starting at 3 gives the cycle , and box 5 holds its own number, which makes a cycle of length 1. The lengths 3, 2 and 1 add up to 6. To check the probability rule, take . There are permutations with a cycle of length 3 and with a cycle of length 4, out of , so the probabilities are and , as the rule says.
Cycle-following strategy
Definition In the cycle-following strategy for the 100 prisoners problem, person first opens box . Whenever the slip shows a number other than , the next box that person opens is box , and the search ends when the slip with appears or after 50 boxes. The boxes opened are and so on, which is the cycle containing , followed from box . The slip with number lies in the last box of that cycle, the one that leads back to box , so person finds it on opening number , where is the length of the cycle containing . Hence person succeeds exactly when that cycle has length at most 50, and the whole group wins exactly when every cycle of has length at most 50. The group loses exactly when there is a cycle of some length from 51 to 100. No two of these 50 cases can happen together, because two such cycles would need more than 100 numbers, and each has probability , so
Each person alone still succeeds with probability exactly , because the cycle containing person is equally likely to have any length from 1 to 100. For each length , the other members of that cycle can be chosen and placed after in ways and the remaining numbers arranged in ways, which multiply to , one hundredth of all permutations. With people who may each open boxes, the same argument gives the winning probability
which is for two people and decreases as grows, approaching without ever reaching it. The calculation needs every rule of the puzzle and the uniformly random arrangement. If whoever fills the boxes knows the strategy and wants it to fail, putting all 100 numbers in one cycle defeats it every time. The group can protect itself by agreeing on a uniformly random permutation , chosen independently of the arrangement and kept secret from whoever fills the boxes. Person then starts at box and, after finding a number other than , opens box next. For every arrangement of the slips, the group then wins with the same probability, about .
In plain words Each person walks around their own loop of boxes and meets their number just before the loop closes. People in a loop of at most 50 boxes all succeed, and people in a longer loop all fail, so the whole outcome depends on one feature of the arrangement, the length of its longest cycle. The strategy changes nothing in the boxes and sends no messages. It only makes everyone read the same hidden structure in the same way.
Example Return to the six boxes holding 4, 1, 6, 2, 5 and 3, and let each person open at most 3 boxes. Person 1 opens box 1 and finds 4, opens box 4 and finds 2, then opens box 2 and finds 1. Person 4 goes around the same cycle from a different point, opening boxes 4, 2 and 1, and person 2 opens boxes 2, 1 and 4. Persons 3 and 6 need two openings each and person 5 needs one, so all six succeed. If the boxes held 2, 3, 4, 1, 5 and 6 instead, the cycle would have length 4, and persons 1, 2, 3 and 4 would all fail while persons 5 and 6 succeed. Over all 720 arrangements of six boxes, cycle following wins in 276, in agreement with the formula,
Random searching, with 3 of the 6 boxes per person, would win with probability only .
Check yourself
- Change the numbers. Eight people play with eight boxes, and each may open four of them. Find the probability that the cycle-following strategy wins, and compare it with random searching.
Show the answer
The group loses exactly when the permutation has a cycle of length 5, 6, 7 or 8. Each of these lengths is more than half of 8, so at most one such cycle can occur, and a cycle of length appears with probability . The four failure probabilities add up to
so the group wins with probability , about . In other words, 14,736 of the 40,320 arrangements lead to a win. Random searching wins only when all eight people succeed, each with probability independently, which has probability , about . Cycle following is about 94 times as likely to win. The value for eight people is higher than the one for 100, as expected from the decrease toward .
- Change one rule. Suppose everyone agrees to start at box 1, not at the box with their own number, and then follows the numbers as before, with at most 50 openings each. What is the probability that the group wins?
Show the answer
The probability is 0. Everyone now opens the same boxes in the same order, box 1, then the box named by its slip, and so on, and a person stops early only on finding their own number. So every search stays within the same first 50 boxes along the path from box 1. Those boxes hold at most 50 different numbers, so at most 50 people can find their own number, and the group always loses. Starting at your own box is what makes the plan work. The slip with your number lies in the box that leads back to your box, so your path is sure to reach it, and the only question is how long that path is.
- Extend the plan. Keep 100 people, but allow each of them to open boxes, where is between 50 and 100. What is the smallest for which cycle following wins with probability at least one half?
Show the answer
With openings, person succeeds exactly when the cycle containing has length at most , so the group loses exactly when some cycle is longer than . Because , every such cycle is longer than half of 100, so at most one can occur, and
For the sum of through is about , so the group wins with probability about . For the sum loses the term , and the winning probability rises to about . The smallest such is 61. The sum is close to , which equals at , so the answer matches what the logarithm suggests. For below 50 this formula no longer applies, because several long cycles could then occur together, and the sum would count such arrangements more than once.