This is a fairly new problem, being traced back to as recently as 2003. However, it also has the kind of counter-intuitive solution that has made it a favourite on mathematical websites and forums. In its various retellings, it sometimes suffers from a lack of stringent conditions that result in rather imaginative solutions; perfectly legitimate solutions within the parameters set but not always the ‘classic’ one. If you’ve seen this before, then speed-read to the end where we take the side of the jailer!

The problem

A jailer with too much time on his hands and a predilection for macabre puzzles decides to play a game with the 100 prisoners in his wing. He tells them that there is a room in the prison that has 100 lockers, each numbered from 1 to 100. Within each locker he will place a piece of paper with the name of one of the prisoners written on it. Each locker will have just one name inside it and each name will only be written down once. Each prisoner is then allowed to enter the room alone and open up to 50 of the lockers. If he finds his name written in one of the lockers he must remember the number of that locker. He is then escorted out of the room through a second exit door and the next prisoner is allowed to enter. Once in the locker room, each prisoner can have no contact with any other prisoners, either coming after him or having gone before him. The prisoners are not allowed to do anything that may leave a message to other prisoners or in any way move the lockers or tamper with them. The jailer watches the game unfold on monitors linked to cameras inside the locker room; other guards escort the prisoners in and out but they have no idea of the order of the name-cards.

At the end of the game, once all 100 prisoners have filed in, opened at least 50 locker doors, read the name in each one and then filed out again, the jailer asks each of them which number locker had their name in it. If they all know the correct locker, they are all free; if at least one of them fails, then they can all look forward to 10 more years in jail! After explaining to the prisoners the rules of the game, the jailer leaves them to discuss any strategy they may wish to devise. The game will start the following morning.

On the face of it, the odds are not in the prisoners’ favour. If the names are assigned randomly and each prisoner opens his maximum allocation of 50 lockers, the probability that each prisoner will find his name is 1/2. The probability that all 100 prisoners will have found their name is therefore (1/2)100. This is pitifully small and all but condemns the prisoners to another decade of incarceration.

However, there is a strategy that greatly increases the chances of the prisoners gaining their freedom. Even with this strategy, it is still not a fair game but it does give the prisoners a chance of freedom that is greater than 30%. What is this strategy?

While the prisoners are feverishly figuring out their plan, the jailer sits calmly in his office sporting a broad grin. He is imagining how excited the prisoners must feel once they discover the optimum solution to their problem. They will realise that they don’t really have a fair chance of success but that at least they have a fighting chance. But the jailer knows all this; he has played the game before and knows the solution. He also knows that they will lose! How can the jailer be so sure that the strategy of the prisoners will fail?

As the jailer plays back in his mind his past games, his grin turns into a grimace as he recalls the time he let his simpleton underling distribute the name-cards in the lockers. It was a fatal error and the jailer blames his own laziness rather than the innumeracy of his former subordinate. But the sting of seeing all those prisoners walk free can never be truly healed, merely inflicted upon others. What did his subordinate do that followed the jailer’s instructions but made it easy for the prisoners to win? There are a number of solutions to this last question, in decreasing order of ineptitude!