I'm a bit sleepy, but I can't get this to work. For 3 prisoners, what if the sequence is (P1 T P1 T P1 T P1 T P2 P2 P2 P2)? Where T is the tally keeper. They've all gone the same number of times (given enough time), but the tally keeper would declare that they had all flipped a switch before P2 had gone in at all. Thus, alligators.
Did I miss something?
The prisoners will only turn on switch A twice. After that they will leave it, and rather toggle the B switch.
Each person will only toggle A to the 'on' state twice.
ah, yes. It even says it right there in the article. Thanks!
Doesn't this solution make the assumption that the guard will continue to pick prisoners to enter the switchroom indefinitely? If he picked P1, P2, P1, P2, Counter, Counter, <end> would the solution still work?
This assumption is part of the original puzzle: "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."
I'm not seeing why they need to turn the switch ON twice. Couldn't they flip the switch only once and have the counter wait for <number of prisoners> ONs (N - 1 + 1)?
Because the switches start in an unknown state. So the first time the counter enters the room and sees switch A on he has no way to know if that's because another prisoner turned it on, or because he's the first one in the room and it started in the on position.
No, then he could have only counted 21 prisoners (43 = 1 initial + 21 * 2). The system will "stabilize" at either 44 or 45 "offs", depending on the initial state.
The answer explains this. The number should be (p - 1) x 2 where p is the number of prisoners. (23-1) = 22 * 2 = 44
But would it not be sufficient to count p?
If switch A starts out in the ON position it would equal one 'fake' prisoner. If the counter just counts one extra (which equals p - 1 (himself) + 1 (fake prisoner) = p) it should be enough, no?
The issue is that the counter doesn't know the state of the first switch at the start. If it's on at the start, then sure your solution will work. But if it's off at the start and they all agree to only flip on the switch once, then the counter will sit around forever waiting for p flips, when only p - 1 will ever happen. They need a solution that will work no matter what state the switch is in at the start.
I don't see this working, if the prisoner who flipped the switch on is brought back into the room immediately after the counter turns it off, then that one prisoner will be assumed to be two different people.
> '"Now I want each of you to flick Switch A to the "On" position twice, and only twice. So if you go in there and Switch A is already on, that doesn't count. I want each of you to actually flick it "On" two times. You got that?"'