A warden wants to play a game with his prisoners.
He tells them that they have to tell him the color of their own hats if they want to have dinner.
note: The warden may be mean, but the prison has a good cook; everyone wants dinner.
The rules of the game:
1 The prisoners get blindfolded, and positioned on a line by the warden.
2 Then everyone gets supplied a red, green or yellow hat. The warden makes sure the prisoners cannot see their own hat.
note: He has plenty of those hats, he may give everyone a yellow one if he feels like it.
3 Everyone then may remove the blindfold.
4 Everyone may only look straight ahead during the game.
note: So the prisoners have no idea how the people behind them are organized, they know however how many prisoners are participating.
note: The prisoners can see all the hats/persons before them.
5 Then everyone may give one hint.
The prisoners know the warden may end the game any time, so they don't dare say to much.
The hints they give are (in this order):
Alice says : I see two green hats
Bob says: I see two red hats
Carol says: Bob and Ernest wear the same hat
Dennis says: Ernest does not know the color of his hat
Ernest says: I know the color of my hat
Ernest probably should not have said that, because the warden stops the game.
Now everyone has to state the color of their own hat.
Luckily everyone knows the color of their own hat.
Please tell me how Ernest can say this.
Bonus points for a solution
note: Yes, you can know the hat colors, even though you are not told were Alice Bob Carol and their fellow inmates are standing.
Clarifications after the first answers:
"I think it is safe to assume that every statement made by the prisoners is not only true, but is provably true": This indeed what you should assume.
"So the prisoners have no idea how the people behind them are organized"; This is supposed to be strict: You cannot deduce the distance or direction of someone behind you talking by the volume of the sound or something similar.
From the solutions brought in:
"we can conclude that Earnest and Dennis are facing each other"
"therefore Ernest must have been facing away from Dennis."
A minor hint:
Both are wrong in their reasoning: You cannot deduce either conclusion from only the statements of Dennis and Ernest. (I may give counter examples in the future)
Nobody talks about prisoner 6, she is so scary even the other prisoners have not dared to ask her name. You can refer to prisoners by number too, the warden does not like you fraternizing with them anyway.
I am convinced a solution requires 7 prisoners.
Seems I made my puzzle too easy, Alaiko just answered his question. I should have said the warden had 5 hats of each color. (bonus: please feel free to solve this harder variant)
Then you still can prove not all prisoners face the same direction. Note that the prisoners can look in opposite directions. The warden placed them "on a line", not "in line" (and blindfolded them since he could not easily start behind all prisoners with his pile of hats during hat distribution.)
Since no one seems to care about unseen prisoners: Some visual clues about what can be proved.
And some more visual clues.
(Sorry, I am a lousy artist)