2026-07-04

Problem — 2026-07-04

Hard

HardLogic

Five prisoners are told they will play the following game tomorrow at noon. They will be arranged in a line, each facing forward, so each prisoner can see everyone in front of them but no one behind. A guard will place either a red or blue hat on each prisoner's head (chosen randomly and independently). No prisoner can see their own hat. Starting from the back of the line, each prisoner must loudly guess their own hat color. Everyone can hear all previous guesses, but no other communication is allowed. Prisoners who guess correctly go free; those who guess incorrectly are executed. The prisoners can agree on a strategy tonight. If they play optimally, what is the expected number of prisoners who will survive?

Express as a decimal or fraction

Show solution
The key insight is that the first prisoner (in back, who can see all 4 hats ahead) should sacrifice themselves to encode information for everyone else. **Optimal Strategy:** The prisoners agree on a parity system. Let red = 0 and blue = 1. Prisoner 5 (back): Counts the number of red hats they see among the 4 prisoners ahead. If this count is even, they say "red"; if odd, they say "blue". This has probability 1/2 of being correct for their own hat. Prisoners 4, 3, 2, 1: Each prisoner can deduce their hat color with certainty using the parity information. **Why this works:** When Prisoner 4 hears Prisoner 5's guess, they know the parity of red hats among {P1, P2, P3, P4}. Prisoner 4 can see {P1, P2, P3}, so they can count red hats there. By comparing: - If the parity of {P1, P2, P3} matches what Prisoner 5 indicated, then Prisoner 4 must have a blue hat - If the parity differs, Prisoner 4 must have a red hat Prisoner 4 announces their color (which is correct). Now Prisoner 3 knows the parity was correct among {P1, P2, P3, P4}, can see {P1, P2}, and heard P4's color, so can deduce their own. This continues down the line. **Expected survivors:** - Prisoner 5: survives with probability 1/2 - Prisoners 4, 3, 2, 1: survive with certainty (probability 1 each) Expected number = 1/2 + 1 + 1 + 1 + 1 = **4.5**