**100-Hat Puzzle**

**One hundred persons will be lined up single file. Each person will be assigned either a red hat or a blue hat. No one can see the color of his or her own hat. However, each person is able to see the color of the hat worn by every person in front of him or her. **

**Beginning with the last person in line, each will be asked to name the color of his or her own hat. If the color is correctly named, the person lives; if incorrectly named, the person is shot dead on the spot. Everyone in line is able to hear every response as well as hear the gunshot; **

**Before being lined up, the 100 persons are allowed to discuss strategy, with an eye toward developing a plan that will allow as many of them as possible to name the correct color of his or her own hat (and thus survive). Once lined up, each person is allowed only to say “Red” or “Blue” when his or her turn arrives, beginning with the last person in line.**

**Develop a plan that allows as many people as possible to live. **

On discussion among themselves , They agree that if the number of red hats that a person can see is even, that person will say red. If they add up to an odd number, he will say blue.

This way number 99 can look ahead and count the red hats. if they add up to an even number and number 100 said red, then 99 must be wearing a blue hat. if they add up to an even number and number 100 said blue, signalling an odd number of red hats, number 99 must also be wearing a red hat.

Number 98 knows that 99 said the correct hat, and so uses that information along with the 97 hats in front to figure out what color hat is on 98 head. And similarly , each of them can predict the color of his hat.

So,at max only one guy who is at back and calling for first time may get killed as his answer depends on number of red hats infront of him.

Though depending on his reply rest all of them will survive.

Its not correct that everyone survives, how about number 100 person how can he predict his own hat color, there is chance that he gets killed… Correct me if i am wrong

Hi Koushik ,

Thanks for replying !!

I suppose no one will be killed … lets take an example

Suppose there are 89 red and 11 blue caps, Now

Case 1 : Last person wearing a red cap

He will see 88 red caps , which is even , and hence will shout “red” which is indeed his hat color

Case 2 : Last person wearing a blue cap :

He will see 89 red caps in front , which is odd, and hence will shout “blue” which is indeed his hat color

And this sequence will continue As the next man now knows what last man has said and can count hats in front of him

There is a problem in this solution. If there are 80 red hats and 20 blue hats and if the 100th person is wearing red hat he will count 79 red hats in front of him which is odd but he will say blue in that case. Correct me if I am missing something

No , Nothing wrong in the solution , as at max only one guy who is at back and calling for first time may get killed as his answer depends on number of red hats in front of him.

Though depending on his reply rest all of them will survive.

great