A Similar puzzle exists, see diagram!
W || B W B
The scenario is that 4 prisoners are buried up to their necks! in sand. One of the men is seperated from the others by a wall (represented by ||)they are each wearing either a Black or White (B,W)hat. The Guard says to them "I will kill you all unless one of you tells me the colour of his hat, two are black, two are white"
No questions are asked among the men, yet one man could definately say which colour he was wearing.
Answer...The middle man of the three!
If the man behind him saw two hats the same, he would have shouted the opposite colour. Because he didn't, the middle man knows he is wearing the opposite colour to the man in front of him!!