23 Prisoners, 2 Switches

A warden meets with 23 newly arrived prisoners. He tells them, “You may meet today and plan a strategy. But after today, you will be in isolated cells and will have no communication with one another.

“In the prison is a switch room, which contains two light switches, each of which can be in either the on or the off position. I am not telling you their present positions. The switches are not connected to anything.

“After today, from time to time whenever I feel so inclined, I will select one prisoner at random and escort him to the switch room. This prisoner will select one of the two switches and reverse its position. He must move one, but only one of the switches. He can’t move both, but he can’t move none, either. Then he’ll be led back to his cell.

“No one else will enter the switch room until I lead the next prisoner there, and he’ll be instructed to do the same thing. I’m going to choose prisoners at random. I may choose the same guy three times in a row, or I may jump around and come back.

“But, given enough time, everyone will eventually visit the switch room as many times as everyone else. At any time anyone of you may declare to me, ‘We have all visited the switch room.’

“If it is true, then you will all be set free. If it is false, and somebody has not yet visited the switch room, you will all be executed.”

What strategy do the prisoners devise?


You must maintain an individual tally of the number of times you have flipped switch A to the ON position. This tally will start at 0. Your actions will depend on the state of switch A and the number of times you have switched it ON.

If, when you enter the switch room, switch A is in the OFF position, you must flip it to the ON position if and only if the number of times you have turned switch A to the ON position is either 0 or 1. Upon flipping the switch, increment your individual tally. If switch A is already in the ON position, or if you have already flipped switch A to the ON position twice before, you are to flip switch B, regardless of its position. (Remember, switch B is the sham switch. It conveys no information. Rather, it is used to avoid confounding the signaling abilities of switch A.) In this way, it can be assured that, given enough time, every prisoner will flip switch A to the on position twice, and only twice.