# Black and White Hats Puzzle

This is a classic puzzle known as the “Black and White Hats” puzzle. The solution involves the students devising a strategy beforehand to maximize the number of students who pass the exam.

There is a line of one hundred students, and each student is wearing a hat that is either black or white. Each student can only see the hats of the students standing in front of them but cannot see their own hats or the hats of the students behind them. The class teacher starts questioning the students from the back of the line, asking each student the color of their hat. Passing the final exam depends on correctly identifying the color of their own hat. Students who answer correctly will pass, and those who answer incorrectly will fail. If the students are allowed to discuss a strategy beforehand, what is the maximum number of students that can pass the exam?

### Black and White Hats Puzzle solution

Here is one possible strategy that would allow at least 99 students to pass:

1. The last student in line (i.e., the 100th student) will count the number of black hats they can see in front of them. They will shout out “black” if the number is odd and “white” if the number is even.
2. The 99th student will then count the number of black hats they can see in front of them, including the hat of the 100th student. If the number is odd, they know their hat must be white, since they heard the 100th student shout “black.” If the number is even, they know their hat must be black, since they heard the 100th student shout “white.”
3. Each subsequent student can use the same logic to determine the color of their own hat based on the number of black hats they can see in front of them, including the hats of the students behind them and the color shouted by the previous student.
4. The 100th student has a 50-50 chance of guessing the color of their own hat correctly since they cannot see any hats in front of them.

By using this strategy, at least 99 students can pass the final exam.