See “the puzzle of the two switches” for a seriously hard logic puzzle. This is a variation of the same puzzle to make it even harder.

The puzzle is exactly the same, except that you can no longer assume anything about the initial state of the two switches. Each switch could be off or on.

Your challenge again is to devise a strategy whereby all prisoners can escape.

Solution over the fold.

Solution

Call the switches A and B; you are to execute strategy 1; all other prisoners execute strategy 2.

Strategy 1.

1. If switch A is on, switch it off.
2. If you have now flipped switch A 17 times, type in the exit code (on screen) and escape.
3. Otherwise flip switch B.

Strategy 2.

1. If the screen is blank, type in the exit code (remembered from previous visit) and escape.
2. Otherwise if this is the first or second time you have seen switch A off, switch it on.
3. Otherwise flip switch B.

The solution is similar. You count as each of the other prisoners visits the
room for the first or second time and remembers the code, allowing them to escape
later. You defer your escape until you can be certain they have all visited the room. A count of 16 might mean 8 prisoners with 2 visits each. A count of 18 might never be reached, if switch A was on initially. A count of 17 is your signal to go. A
blank screen is the signal for each of them then to make their escape.