The first three may not all be different.I want to thank you all....I was thinking like this:After the first three prisoners took their right places,they all should be facing the door, the possible combinations would be:Yellow,Green,Red,........Yellow,Green,........,BlueYellow,.........,Red, Blue.........,Green, Red, Blueso when the 4th one enters, Let him to have X color..the X one standing in the raw will turn his face to the wall,and the new comer will stand in that raw facing the door....and when nobody turns to the wall so he should stand at the empty place facing the door.when the four raws are made, each new comer will know where he belongs when the man with the same color turns his face toward the wall.You're right.NS signaling is enough.Four easily distinguishable rotations: None, 180ocw, 180occw, and 360occw.And entering prisoners must be able to see the rotation. I think we spent most of the time on this puzzle with a poor understanding of the conditions.But it was fun to finally solve something possible.It's just that the problem became teasing out the constraints that admitted a solution!Bertrand was helpful in this case.
I'm taking a slightly stricter view, that NEWS coding is not available.
Wolfgang has allowed that prisoners can either face toward or away from the door.
That is, NS (or EW, as I drew it) coding is available, and that requires two prisoners to signal a color.
That presents a particular problem for P2 on initial entry, but I think it can be worked around.
If only a binary signaling scheme is allowed, CaptainEd has shown that only prisoner 1 needs to change his mind. Even in the stricter NS view, there are some latitude to define a quadnary signaling scheme due to an implied necessary conditionSpoiler for becauseThanks, Wolfgang.
What if all the prisoners are say red, except for the last three to make all the colors used?
Edit: ok, that's not a problem I guess, it just delays the row formation.






