This is a famous Prisoners and Hats Puzzle.

4 prisoners are caught and are to be punished. The Judge allows them to be freed if they can solve a puzzle. If they do not, they will be hung. They agreed.

The 4 prisoners are lined up on some steps (as shown). They are all facing in the same direction. A wall separates the fourth man from the other three.

So to summarize:-

Prisoner 1 can see Prisoners 2 and 3.

Prisoner 2 can see Prisoner 3.

Prisoner 3 can see none of the others.

Prisoner 4 can see none of the others.

The prisoners are wearing hats. They are told that there are two white hats and two black hats. The men initially don't know what colour hat they are wearing. They are told to shout out the color of the hat that they are wearing as soon as they know for certain what colour it is.

They are not allowed to turn round or move.

They are not allowed to talk to each other.

They are not allowed to take their hats off.

Who is the first person to shout out and why?

Prisoner 3 and Prisoner 4 are not able to tell what color hats they wear since they can see none of the others.

Prisoner 1 can see Prisoner 2 and Prisoner 3 but is not able to tell what color hat he wears because Prisoner 2 and Prisoner 3 wear different color hats. So Prisoner 1 will not shout out.

Then from Prisoner 1's reaction, Prisoner 2 is able to interpret that he (Prisoner 2) and Prisoner 3 wear different color hats. Since Prisoner 3 wears black color hat, so Prisoner 2 knows he himself wears white color hat.

So the first one to shout out the hat color is Prisoner 2

prisoner 2 will shout first

intresting puzzle...