Red hats, blue hats, dwarves and a goblin – a logic puzzle
100 dwarves are captured by an evil goblin milliner who has an over-abundance of red and blue hats and who really does not like dwarves. Being an evil goblin, he has concocted a fiendish, fiendishly complex game by which he hopes to kill as many of them as possible:
“You must all sit in a line, one behind the other, so that none of you can see any dwarves except the dwarves in front of you. I am going to blind fold each of you perfectly, then put a red or blue hat on your head. Then, I will remove the blind folds. In any order you like, each dwarf must say the colour of the hat they are wearing. If they get it wrong I shall eat them, but if they get it right I will be fair and set them free. However, should any dwarf attempt to see their own hat or say anything other than ‘red’ or ‘blue’ I will kill you all! By the simple laws of probability, I expect to feast on 50 delicious dwarves this evening. Ahahaha! Now, I will go and collect my hats, and you may talk amongst yourselves and ponder your fate. Ahahahaha!”
Assume the goblin is a goblin of his word and will set free any dwarf that guesses the colour of his hat correctly. Assume also that the dwarves are smart and have good memories. What strategy should they use so that as many of them survive as possible, and how many will survive?