
There are 100 criminals in a jail and the jailor gets a change of heart and wants to release them. But he does not want to release them just like that, he wants to play a game with them. He announces that the next day, he will be putting hats, either blue or red, in equal randomness, on each of the prisoner's heads and all the prisoners will be lined up facing in one direction in a single file. So the last prisoner is able to see all the others' hats except of course his, the last but one will be able to see all the others except his and the last prisoner's, and so on...Basically they all can see what is in front of them. The first prisoner is unable to see any prisoner's hat as he is the first guy. The prisoners will be blindfolded until the jailor completes the task of putting the hats and then the blindfold will be removed. Once the blindfolds are removed, the jailor starts from the back and asks the color of the hat the prisoner is wearing. If the prisoner guesses the color of his own hat correctly, he survives, if not he is shot. To make things spicy, lets say the jailor allows others only to hear prisoner say the color of his hat and not whether he was correct or wrong. The prisoners are dismissed for the night. They discuss a strategy and come up with an optimal solution of saving lots of their fellow buddies. To top it all off, the jailor has a microphone bug inside the cell and he is able to hear their plan. So what is the strategy of the prisoners and how do they make sure lots of their folks are saved in the cruel game played by the jailor?
Once you solve the problem, lets try to get a generic methodology for a 'N' prisoner and 'K' different colors of the hats put in random. How many prisoners can be saved at a maximum and how many will be killed at a minimum?
Level: Hard
(Image courtesy: www.londonstimes.us/toons/index_misc.html, I have put in the red and blue hats for those prisoners)