During an ancient war three prisoners were brought into a room. In the room was a large box containing three white hats and two black hats. Each man was blindfolded, and one of the hats was placed on his head.
The men were lined up, one behind the other, facing the wall. The blindfold of the man farthest from the wall (man C) was removed, and he was permitted to look at the hats of the two men in front of him. If he knew (not guessed) the color of the hat on his head, he would be freed. However, he was unable to tell. The blindfold was then taken from the head of the next man (man B), who could see only the hat of the one man in front of him. This man had the same chance for freedom, but he, too, was unable to tell the color of his hat. The remaining man (man A) then told the guards the color of the hat he was wearing and was released. What color hat was he wearing, and how did he know?