# Black and White Hats Puzzle - Three prisoners

There is a similar question here but with four prisoners. But I am not able to understand the logic. The original question is here. My solution is half way through. Since there are 3 Back Hats (B) and 2 White Hats (W), the various combinations possible include:

BBB (Meaning all 3 prisoners wear black hats)
BBW
BWB
WBB
WWB
WBW
BWW


From these possibilities, the combinations WWB, WBW and BWW are filtered (the possibility of 2 Black hats remaining and 0 White Hats remaining). Now, how do I proceed to determine the color of the hat of the front prisioner?

Suppose that the rear man sees his two friends wearing two white hats. Then he would be able to tell the color of his hat.
In this case, he answers "I don't know", so we deduce that his friends aren't wearing white hats.
Now, the middle man knows that, if the guy in front of him is white, he (the guy in the middle) cannot be white. If the 3rd guy was black, the man in the middle would indeed be able to answer.
Though, he said "I don't know", so the third guy isn't white. The middle guy has no information about his hat, as we know.
Finally, it's time for the last guy to answer. Listening to the previous answers, he can deduce that he is black and answers!

If you want a solution that analyzes the other cases one by one, here is it:

• BBB The first says "I don't know", implicitly stating that the other two aren't both white. The second man, seeing a black hat in front of him, doesn't know the color of his hat. The third guy, knowing that he can't be white, deduces his color (black).
• BBW As in the previous case, the first says "I don't know". The second, seeing a white hat, deduces that he is black and answers.
• BWB The first says "I don't know". The second doesn't know as well. As in BBB, the third knows that he must be necessarily black.
• WBB The first says "I don't know". The second doesn't know too. The third answers "black" consequently, same reason as before.
• WWB The first doesn't know. The second neither. As before, the third answers "black".
• WBW The first doesn't know. The second, seeing a white hat in front of him, answers "black".
• BWW The first sees two white hats, thus he must be black!