Nice variant of this question (but same concept) right here:

http://www.programmerinterview.com/index.php/puzzles/hat-puzzle-black-and-white-hats/

]]>We can extend this to protect ever longer groups of prisoners. The first in any odd sized group (3,5,7,…) needs only determine whether the group (minus him) is composed of adding odd red hats and odd blue hats,or even red hats and even blue hats. Call blue for evens, red for odds. The rest add up what they see and what they hear and call red or blue based on whatever will make sure the result is parity (blue0 or not parity (red).

It would be possible to pick an arbitrarily large group (and only have one prisoner take a risk) but because people are human and all this calculating can lead to errors which would be catastrophic, I would tend to keep the groups small. But, now we have a strategy that matches whatever size of group feels they can handle the quick math.

]]>There’s also an interesting moral dilemma if the first prisoner finds out the color of his hat accidentally, and determines that he must either kill himself so that the other 99 live, or he lives and the other 99 die…

Then there’s the practical problem of trusting each prisoner to do this kind of math correctly. If you performed this experiment with real people, at least a couple would mess up the calculation, causing strings of deaths until someone messes up again and corrects the sequence.

In practice, the safest thing is probably to have each odd prisoner state the hat color of the even-numbered prisoner directly in front, and each even-numbered prisoner state the previously stated color. In this way, 50 prisoners will assuredly live, and the other 50 would live half the time (expect 75 to live), and the complexity of the solution fits into even the simplest mind! ðŸ™‚

]]>If (the number of people behind who called blue) + (the number of people ahead who have blue hats) is even, then your hat is blue, otherwise it’s red. I am still having trouble explaining why this seems to work, but here are some more samples:

```
b b b b
0 1 2 3
0: 0 + 3: red
1: 0 + 2: blue
2: 1 + 1: blue
3: 2 + 0: blue
r r r r
0 1 2 3
0: 0 + 0: blue
1: 1 + 0: red
2: 1 + 0: red
3: 1 + 0: red
r r b b
0 1 2 3
0: 0 + 2: blue
1: 1 + 2: red
2: 1 + 1: blue
3: 2 + 0: blue
b b r r
0 1 2 3
0: 0 + 1: red
1: 0 + 0: blue
2: 1 + 0: red
3: 1 + 0: red
```

There are a couple patterns.

]]>The real answer is: the maximum guys that has to die is 7 (taking the worst senario), the minimum is 0.

ðŸ™‚ think……

]]>