Home > Riddles > The hundred prisoners with hats

The hundred prisoners with hats

Master playsLevel 3/5

It is a problem of collective discipline under fierce restriction: a single word per person and almost no second chances. Beauty appears when the group stops trying to save themselves one by one and begins to think as a whole.

There are 100 prisoners in line. Each one is randomly placed with a red or blue hat.

Each prisoner can see the hats of everyone in front of him, but not his own or those behind him. Starting with the last person in the line and moving forward, each person must say a single word out loud: “red” or “blue.” They can't say anything else.

If someone guesses the color of his hat correctly, he survives; If you fail, you die. Before starting you can agree on a strategy.

What is the best possible strategy and how many lives does it guarantee?

Hints

Show hints
  1. The first speaker cannot guarantee his own salvation, so his role is different.
  2. Do not try to convey a specific color: it is advisable to leave global information.
  3. This information must be able to be updated with each subsequent response.

Solution

Show full solution

Answer: They can guarantee the salvation of 99 prisoners. Explanation: Before starting, agree on this rule: the last person in line will use his word not to confidently guess his own hat, but to communicate the parity of the number of red hats he sees in front of him. For example, you can say “red” if you see an odd number of reds and “blue” if you see an even number. That first prisoner cannot ensure his life, but he leaves global information. From there, each prisoner combines:

  • the parity announced at the beginning,
  • the hats you see in front,
  • and the answers already given behind. With that he deduces with certainty the color of his own hat and corrects the parity for the following ones. Thus, the first one may fail, but the other 99 are determined without error.

Related riddles

Keep practicing

If you enjoyed this one, try more pure-logic riddles, explore this theme, browse the full archive, or read the riddle-solving guide.

← Previous: The hundred boxes numbered · Next: The light-bulb room →