News for hackers. Stuff that matters.
Re:Prison Switcharoo by lisper on Sunday February 23, 2014 @11:29AM (#7286383)
Re:Prison Switcharoo by michael_h on Sunday February 23, 2014 @01:39PM (#7286927)
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?

Re:Prison Switcharoo by daeken on Sunday February 23, 2014 @01:49PM (#7286984)
Each person will only toggle A to the 'on' state twice.
Re:Prison Switcharoo by michael_h on Sunday February 23, 2014 @08:47PM (#7288669)
ah, yes. It even says it right there in the article. Thanks!
Re:Prison Switcharoo by TobbenTM on Sunday February 23, 2014 @01:47PM (#7286978)
The prisoners will only turn on switch A twice. After that they will leave it, and rather toggle the B switch.
Re:Prison Switcharoo by ironmagma on Sunday February 23, 2014 @03:09PM (#7287352)
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?
Re:Prison Switcharoo by vanschelven on Sunday February 23, 2014 @04:41PM (#7287729)
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."
Re:Prison Switcharoo by codyps on Monday February 24, 2014 @05:52AM (#7290116)
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)?
Re:Prison Switcharoo by lisper on Monday February 24, 2014 @12:47PM (#7292163)
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.
Re:Prison Switcharoo by mischanix on Sunday February 23, 2014 @03:42PM (#7287496)
And here's the answer in Go: http://play.golang.org/p/m_biT7Dfmo
Re:Prison Switcharoo by no_wave on Sunday February 23, 2014 @12:07PM (#7286531)
It should be 43 instead of 44, right?
Re:Prison Switcharoo by colanderman on Sunday February 23, 2014 @12:29PM (#7286602)
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.
Re:Prison Switcharoo by delinka on Sunday February 23, 2014 @01:07PM (#7286759)
The answer explains this. The number should be (p - 1) x 2 where p is the number of prisoners. (23-1) = 22 * 2 = 44
Re:Prison Switcharoo by TobbenTM on Sunday February 23, 2014 @01:52PM (#7286997)
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?

Re:Prison Switcharoo by Serplat on Sunday February 23, 2014 @02:15PM (#7287122)
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.
Re:Prison Switcharoo by joenathan on Sunday February 23, 2014 @03:46PM (#7287515)
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.
Re:Prison Switcharoo by christiangenco on Sunday February 23, 2014 @04:23PM (#7287652)
> '"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?"'