# Hat puzzle - 7 prisoners

There are 7 prisoners buried up to their necks in sand. 6 are on one side of a wall, all facing the wall. They are lined up such that the furthest from the wall can see the 5 prisoners closest to the wall, the next furthest can see the 4 prisoners closest to the wall, and so on. This means the closest prisoner to the wall cannot see anyone else. The 7th prisoner is on the other side of the wall, and is in isolation.

Here’s the information they have been given:

• They are all logical logicians

• There are 7 total prisoners

• They are all wearing hats

• There are only three hat colors: red, white, and blue

• There are at most 3 hats of the same color, and at least 2 of the same color

• A prisoner can be freed only if they say their own hat color

What is the best possible scenario for the prisoners? How many go free?

What is the worst possible scenario for the prisoners? How many go free?

• For both questions, do we assume that they use the optimal strategy? Dec 10, 2017 at 11:50
• Actually, it's pretty obvious that the best possible scenario is that they all go free. That's possible so is obviously a scenario that can happen Dec 10, 2017 at 11:51
• What's the "protocol" here? Do they get to talk to one another, or just guess hat colours? Do they guess all at once, or one by one? Do they have to guess in a particular order? Dec 10, 2017 at 12:07
• @GarethMcCaughan @ Oray It is a strange variant of prisoners and hats puzzle. Dec 10, 2017 at 18:06
• I'm voting to delete the last comment due to its use of "ambiguositiveness" in place of the actual word, ambiguity. :)
– Rubio
Dec 12, 2017 at 8:38

# Best case scenario:

Result:

They all go free (except/including 7, see 7's case bellow).

1:

Obvious

2:

Since 1 said red, then 1 must be sure he got red, the only way for that to happen is if 2 has the same color as 3. So 2 will say green.

3:

Since 1 said red, 2 and 3 must have the same color. Since 2 said green, 3 will too say green.

4, 5 and 6:

The only way the others would have deduced their hat colors is if 4, 5 and 6 have the same hat color (I mean if 4 has a red had, no one would've deduced their hat color, if 4 has a green hat then 2 wouldn't have deduced his hat color). So 4 has a blue hat and so does 5 and 6.

7:

If 7 can hear through the wall then he will say red. If not he will stay in prison.

• @R.M The three colors I used are the three colored squares (red, green and blue). The uncolored hats means the color doesn't matter (whatever the color is the statements are true). Dec 10, 2017 at 17:45
• In that case, 3 would know that his hat is blue, because otherwise 2 would know that his hat is blue, because otherwise 1 would know that his hat is blue, because you need at least 2 blue hats. So it's not actually worst case scenario. Dec 10, 2017 at 18:21
• I.e. if 1 doesn't know which color hat he has, it means that he sees at least 1 blue hat. Same for 2. Therefore, 3 knows that 2 sees a blue hat, but 4, 5, and 6 don't wear blue hats. So 3 would know that he has a blue hat. Dec 10, 2017 at 18:27
• @R.M Yeah, you're right. 3 will know for sure. Removed the worst case scenario altogether. Dec 10, 2017 at 18:30

For best case scenario, see Ibrahim's answer (but replace green with white in your mind!).

# Worst case Scenario

R W B R W B | R

Because:

Everyone understands that this is one possibility, but they have other possibilities in mind.

## 1 thinks:

I could have any other hat, too.

## 2 thinks:

I could switch hats with 1, and he still wouldn't know which one he is.

## N thinks (where N is an integer from 3 to 6):

I could switch hats with (N-1), and he still wouldn't know which one he is. And all the previous prisoners would still see the same hats.

In each case above:

No matter how the hats are exchanged, every previous prisoner will see one or two of each color. Because of this, they won't be able to tell which one they are. So everyone knows at least 2 possibilities.

## 7 thinks:

I could be anything.

So:

Nobody gets to leave.

• The last statement is not exactly true, each prisoner still has a 1/3 chance to go free.
– Rick
Sep 6, 2018 at 7:07