no the solution doesn't fail.
Sorry. I must have missed something in the instructions. This solution only works when there are 10 black hats and 10 red hats. No where in the instructions does it say this. The solution fails if there are different numbers of black and red hats. There could be 19 black hats and 1 red hat.
suppose there are 19 black and 1 red hat
then 20th last prisoner shouts black (key word for black being odd)
he does not know his own hats colour so he may or may not be saved
but the 19th prisoner knows that including his hat there are odd number of black hats, now if he sees even black hats, his hats colour is black, but if he sees odd black colours, his hat colour is red
now suppose he sees odd black colour, then he shouts red
the others keep on counting, this red means red is now odd (key word for red being odd)
the others would keep a note of it and carry on like wise
Edited by vivekkumarjha, 13 June 2012 - 06:37 PM.