My question, which I do not know the answer to, concerns the classic 100 prisoners and 100 boxes puzzle, summarized below. The solution to this assumes the names are placed in boxes randomly, and gets a ~30% probability of success.

My question is what happens if the warden can choose how to place the names in the boxes, instead of placing them randomly? Now this is a sort of game theory question. The prisoners can no longer use the same strategy, since the warden can guarantee it fails by placing the names in a long cycle.

Edit: Furthermore, assume that the warden is fully aware of the prisoners' plan, and can use this information to inform his placement. The problem is trivial otherwise; the warden needs this info to defeat the 30% strategy.

So, my question is,

What is the best strategy for the prisoners, where the goodness of a strategy is measured as its worst case probability of success against all possible warden strategies, including random ones?

As a warm-up which I cannot solve, what is the prisoner's best strategy if the warden randomly places the names in boxes so the resulting permutation is one of the $99!$ possible cycles of length $100$?

Original puzzle:

100 Prisoners and Boxes

A warden explains to 100 prisoners that he will bring them one by one into a room with 100 boxes. Each prisoners' name will be written on a piece of paper, then the slips will be randomly be placed in the boxes, one name per box. When the prisoner is brought into the room, they may open up to 50 boxes. Afterwards, they leave the room without getting to talk to any of the other prisoners, and the warden closes all the opened boxes (and generally resets the room).

The prisoners win only if every prisoner opens the box containing their name. Before the trial begins, the prisoners may confer and decide on a strategy. How can they win with a fairly good probability? You can do much better than the random strategy, with probability $1/2^{100}$.

  • $\begingroup$ What is the probability space? Is the prisoners' strategy necessarily random? Otherwise, for any deterministic strategy, won't the "worst case" warden strategy always result in failure? $\endgroup$
    – noedne
    Commented Apr 16, 2019 at 8:06
  • $\begingroup$ Does the warden get to know every single detail of the prisoners' plan, including the numbers assigned to each prisoner? $\endgroup$
    – Bass
    Commented Apr 16, 2019 at 8:43
  • 1
    $\begingroup$ In the original problem, it does not actually matter how the names are placed in the boxes. The randomness comes from the assignment of prisoners to numbers in the prisoners' strategy. It only makes sense to talk about the "resulting permutation" if the prisoners' have already assigned these numbers, in which case their strategy is doomed to fail. $\endgroup$
    – noedne
    Commented Apr 16, 2019 at 9:18
  • $\begingroup$ @noedne Ohhh, yes I see. Unless we assume the warden has full knowledge of the prisoners' plan, the problem is trivial. I will edit to make this clear. $\endgroup$ Commented Apr 16, 2019 at 14:48

2 Answers 2


I assume that the prisoners decide on a strategy in the presence of the warden, and that they cannot communicate after this. (So the prisoners cannot have any common secrets that the warden does not know about.) Now the warden can distribute the names over the boxes using their knowledge of the strategy. Under these assumptions the optimal strategy of the prisoners gives a success probability of


A possible strategy to get this probability is

the random strategy where each prisoner picks 50 random boxes.

A proof that this is indeed optimal:

Let $P$ be the set of $100$ prisoners, and let $D$ be the set of $100!$ possible distributions of the names over the boxes. For a prisoner $p \in P$ and a distribution $d \in D$, let $q_{pd}$ be the probability that $p$ finds their own name in distribution $d$ using the chosen strategy. Now the probability that all the prisoners find their own name with distribution $d$ equals $\prod_{p \in P} q_{pd}$, there is namely no dependence between the outcomes for the different prisoners.
Since the warden knows the complete strategy, they also know all probabilities $q_{pd}$, so they can choose the distribution $d$ for which the success probability $\prod_{p \in P} q_{pd}$ is minimized; let this minimal success probability be denoted by $q$. Now we can do some computations to give an upper bound on $q$, first we see that
$$q^{100!} \leq \prod_{d \in D} \prod_{p \in P} q_{pd} = \prod_{p \in P} \prod_{d \in D} q_{pd}.$$ Using AM-GM, we get that for any prisoner $p$ we have $$\prod_{d \in D} q_{pd} \leq \left(\frac{1}{n}\sum_{d \in D} q_{pd}\right)^{100!},$$ here $\frac{1}{n}\sum_{d \in D} q_{pd}$ can be seen to equal the probability that $p$ finds their own name in a random distribution of the names. This does however not depend on $p$'s strategy, when the name distribution is random this probability will always equal $\frac{1}{2}$. So combining all computations we get $$q^{100!} \leq \prod_{p \in P} \prod_{d \in D} q_{pd} \leq \prod_{p \in P} \left(\frac{1}{n}\sum_{d \in D} q_{pd}\right)^{100!} = \prod_{p \in P} \left(\frac{1}{2}\right)^{100!} = \left(\frac{1}{2}\right)^{100! \cdot 100}$$ and therefore $q \leq \left(\frac{1}{2}\right)^{100}$. So we see that the warden always has a strategy that gives a success probability of at most $\left(\frac{1}{2}\right)^{100}$, as claimed.


I have a lateral-thinking solution:

The prisoners all get their names changed to the same name (i.e. "Joe Smith"), so that every single box must contain the name "Joe Smith." The probability of every prisoner opening a box with their name in it is then 100%.

Not a bad probability!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.