Poll
2 votes (40%) | |||
1 vote (20%) | |||
1 vote (20%) | |||
1 vote (20%) | |||
1 vote (20%) | |||
2 votes (40%) | |||
1 vote (20%) | |||
2 votes (40%) | |||
1 vote (20%) | |||
1 vote (20%) |
5 members have voted
Quote: The puzzleThere is a prison with 23 prisoners. The warden brings all the prisoners to a meeting and explains that he set up a room with two switches, labeled A and B. Each can be in an on or off position only. Starting the next day, the warden will pick a prisoner at random, with replacement, once per day. That prisoner will be led to the switches room. He must then switch one, and only one, switch of his choice.
When any member of the group declares "We have all been to the switch room," the warden will check his records to see if it is true. If it is true, then each prisoner will be set free immediately. If not, they will all be given the death penalty immediately.
The warden explains they can have the rest of the day to discuss strategy. Then they will all be separated and will never have a chance to communicate again, except via how they set the switches.
One final detail, the warden will set the switches in their initial state at random and not inform the prisoners beforehand of the initial setting.
Understand? I hope I told it right.
Question 1: What is a strategy that would ensure success?
Question 2: What strategy minimizes the number of expected number of days until freed, starting with the day of the first visit.
As always, no searching!
Also, Please put answers and solutions in spoiler tags
Enjoy.
Whenever someone enters the room who has not yet been in the room and the A switch is up, he switches it down. If he has already been in the room, he switches B (doesn't matter which way). If the A switch is down when he enters the room and this person hasn't yet switched A to down, then he'll wait until next time he enters to switch A down.
Each time the counter goes into the room and the A switch is down, he counts for another person entering the room. If it's up, he knows no new person has entered the room since he last entered the room and his count does not change.
Once he's counted the switch to be "down" when he enters the room 22 times, excluding the first time he enters (where it may be up or down), then he'll know 22 others, himself included, have entered the room. At which point he'll tell the warden they've all been in the room.
Designate one prisoner as "the leader."
Each day, the switches are left alone, except in two cases:
(a) If someone besides the leader enters, and this is the first or second time they have been in the switch room with one switch up and the other switch down, move Switch B so both switches are pointing in the same direction (up or down)
(b) If the leader enters, and both switches are pointing in the same direction, move Switch B so one switch points up and the other points down
If the warden initially had both switches pointing in the same direction, then nobody will do anything until the leader enters for the first time; the leader will set the switches to the "different" state. After that, eventually someone who has not entered at least two times with the switches in the "different" state will set them to the "same" state, and then eventually the leader will return and reset them to the "different" state. If 21 of the prisoners besides the leader have done this twice, but the 22nd has not done this at all, this is 43 changes by the leader, and only the last remaining prisoner will change them again.
If the warden initially had both switches pointing in different directions, then nobody will do anything until somebody besides the leader enters for the first time, in which case the same procedure as above is followed. Once everybody besides the leader has done two changes, that is 44 changes by the leader.
In either case, once the leader has done 44 changes, he will announce that everybody has been in the switch room.
I have seen this problem before, with one switch, and the strategy is the same; replace "both switches in the same direction" with "the switch is up" and "both switches are in different directions" with "the switch is down."
I am still working on the expected number of days, but any answer will have to have two answers - one for each of the initial settings - as the problem says that the initial setting is arbitrary and not random.
OOPS - I read the problem wrong. I didn't notice the requirement about having to switch exactly one switch.
Then again, my revised solution is similar, although I think it takes twice as long as RS's:
Use the "one switch" strategy stated in my answer, using Switch A; if a prisoner would normally "do nothing," change Switch B instead.
Then again again, I think RS's solution has a flaw:
Suppose Switch A starts down. On day 1, prisoner 2 enters, and changes switch B. On day 2, the counter (whom I will call "prisoner 1") enters, moves Switch A up, and starts his count at 1. On day 3, prisoner 2 enters again, sees Switch A up, and moves it down. On day 4, the counter enters, moves Switch A up, and now the count is 2. The next 40 days alternate between a new prisoner moving Switch A down and the counter moving it back up. After day 44, the counter has counted 22 changes - but only 21 of the prisoners besides the counter have been in the room.
Quote: RSFirst person to go in the room is the counter. He makes sure Switch A is always "up" when he leaves. If it's already up, he leaves it up and switches B (doesn't matter if B goes up or down).
Whenever someone enters the room who has not yet been in the room and the A switch is up, he switches it down. If he has already been in the room, he switches B (doesn't matter which way). If the A switch is down when he enters the room and this person hasn't yet switched A to down, then he'll wait until next time he enters to switch A down.
Each time the counter goes into the room and the A switch is down, he counts for another person entering the room. If it's up, he knows no new person has entered the room since he last entered the room and his count does not change.
Once he's counted the switch to be "down" when he enters the room 22 times, excluding the first time he enters (where it may be up or down), then he'll know 22 others, himself included, have entered the room. At which point he'll tell the warden they've all been in the room.
I agree with this solution. Actually, it should take 0.956521739 less days than mine. Congratulations!
Quote: WizardI agree with this solution. Actually, it should take 0.956521739 less days than mine. Congratulations!
I believe I am following the proposed solution in the following case:
Number the prisoners 1-23; #1 is the counter
The values in parentheses are the status of switch A, the status of switch B, and the count, after that day's switch is moved
Day 0: both switches are down
Day 1: #2 enters, sees switch A is down, and moves B up (down/up/0)
Day 2: #1 enters, sees switch A is down, and moves A up (up/up/1)
Day 3: #2 enters, sees switch A is up, and moves A down (down/up/1)
Day 4: #1 enters, sees switch A is down, and moves A up (up/up/2)
Day 5: #3 enters, sees switch A is up, and moves A down (down/up/2)
Day 6: #1 enters, sees switch A is down, and moves A up (up/up/3)
Day 7: #4 enters, sees switch A is up, and moves A down (down/up/3)
Day 8: #1 enters, sees switch A is down, and moves A up (up/up/4)
...
Day 41: #21 enters, sees switch A is up, and moves A down (down/up/20)
Day 42: #1 enters, sees switch A is down, and moves A up (up/up/21)
Day 43: #22 enters, sees switch A is up, and moves A down (down/up/21)
Day 44: #1 enters, sees switch A is down, and moves A up (up/up/22)
Counter: "Everybody has been in the switch room"
Warden: "When did prisoner 23 enter the switch room?"
That means that prisoner is eligable to be randomly selected again on the next drawing.Quote: TumblingBonesNot sure what you mean by "pick a prisoner at random, with replacement". Could you clarify?
In terms of a marble example, the easiest... You have a bag of 9 red marbles and 1 blue marble. What are your odds of drawing the blue marble? 1/10... Now, let's say WITHOUT REPLACEMENT. After the first drawing you did NOT put the marble back in, so now there are 9 total marbles remaining. Assuming you picked a red marble first, now your odds of drawing the blue marble are 1/9, instead of 1/10.
With Replacement means your drawings go back in the bag. So say you draw a red marble on the 1st draw... now it goes back in the bag so there are still 10 marbles total. So on draw #2 WITH REPLACEMENT your odds of drawing the blue marble are again still 1/10.
Quote: RomesThat means that prisoner is eligable to be randomly selected again on the next drawing.Quote: TumblingBonesNot sure what you mean by "pick a prisoner at random, with replacement". Could you clarify?
Thanks! This stirs up a long lost memory from an Into to Algorithms class many eons ago.
Quote: ThatDonGuy
I believe I am following the proposed solution in the following case:
Number the prisoners 1-23; #1 is the counter
The values in parentheses are the status of switch A, the status of switch B, and the count, after that day's switch is moved
Day 0: both switches are down
Day 1: #2 enters, sees switch A is down, and moves B up (down/up/0)
Day 2: #1 enters, sees switch A is down, and moves A up (up/up/1)
Day 3: #2 enters, sees switch A is up, and moves A down (down/up/1)
Day 4: #1 enters, sees switch A is down, and moves A up (up/up/2)
Day 5: #3 enters, sees switch A is up, and moves A down (down/up/2)
Day 6: #1 enters, sees switch A is down, and moves A up (up/up/3)
Day 7: #4 enters, sees switch A is up, and moves A down (down/up/3)
Day 8: #1 enters, sees switch A is down, and moves A up (up/up/4)
...
Day 41: #21 enters, sees switch A is up, and moves A down (down/up/20)
Day 42: #1 enters, sees switch A is down, and moves A up (up/up/21)
Day 43: #22 enters, sees switch A is up, and moves A down (down/up/21)
Day 44: #1 enters, sees switch A is down, and moves A up (up/up/22)
Counter: "Everybody has been in the switch room"
Warden: "When did prisoner 23 enter the switch room?"
In this case, "person #2" is deemed the counter -- whomever the warden picks to go in on day #1.
Quote: RSIn this case, "person #2" is deemed the counter -- whomever the warden picks to go in on day #1.
Looks like I'm the one who is mistaken, then - the version of the problem I am familiar with did not make the assumption that there had to be someone put into the room every day, so the counter had to be designated in advance.
You can have one of the N+3 or thereabouts beers that Wizard owes me.
Quote: TumblingBonesNot sure what you mean by "pick a prisoner at random, with replacement". Could you clarify?
Romes gave a good answer. Sorry to use that terminology but I've taken too many statistics classes to forget it.
Quote: ThatDonGuyLooks like I'm the one who is mistaken, then - the version of the problem I am familiar with did not make the assumption that there had to be someone put into the room every day, so the counter had to be designated in advance.
You can have one of the N+3 or thereabouts beers that Wizard owes me.
How would you solve this problem if a prisoner did not have to enter every day?
Quote: RSHow would you solve this problem if a prisoner did not have to enter every day?
My original answer solved this - short version: you have to wait until everybody has entered twice.
Designate someone in advance as the counter.
When someone other than the counter enters:
If switch A is down, and this is the first or second time this prisoner has entered the room with switch A down, move switch A up.
Otherwise, move switch B.
When the counter enters:
If switch A is down, move switch B.
If switch A is up, move switch A down, and add 1 to the count (starting at zero).
If the count is 44, inform the warden that everyone has been into the switch room.
If Switch A is initially down, then it will be moved up by the first person other than the counter to enter, and will remain up until the counter enters. Since the other 23 do not move the switch after they have entered the room twice with the switch down, when the count is 44, everybody besides the counter will have entered at least twice.
The reason the non-counters move Switch A twice instead of just once, and the counter stop at 22, is, if Switch A is initially up, then when the count is 22, there is no guarantee that more than 21 prisoners besides the counter have been in the room. If Switch A is initially up, and 21 of the other 22 prisoners enter twice with Switch A down, the count is 43 (1 for the initial setting and 42 for the other prisoners moving it); when the remaining prisoner enters for the first time with Switch A down, the count will be 44 when the counter enters again.
In some versions of the puzzle, the prisoners know the initial state of the switches, in which case the "every non-counter switches it only once, and the counter stops at 22" strategy works; if Switch A is initially up, the non-counters are told to move it down the first time they enter with it up, and the counter will move it up when it is down.
I assume you're referring to my answer?Quote: RSLet's say no one entered the room on day #1. How is the entering prisoner on day #2 supposed to know whether he's the first to enter or another prisoner has already entered and switched it down? What if on day #20, the counter enters the room, but he's the first one to enter the room?
The answer to the first one is, he doesn't have to know. If it's down, he leaves it alone, and moves the other switch. Whether it was down from the beginning or someone else moved it down is irrelevant. That's why the counter has to count to 44 instead of just 22.
The answer to the second one is, it's the same as if he was the first to enter the room on day 1, or day 19, or day 256. The counter has no way of knowing whether or not anyone has entered the room and moved Switch A - and remember that both "the counter is the first to enter" and "Switch A was down from from the beginning" are both possible.
If you know the first day on which someone will definitely enter the room, the solution becomes, everybody who enters before that day moves switch B, and then it becomes your solution to the original problem.
Then it's going to take longer for them to get freed. It's possible that all of them could die before all of them enter the room - very, very unlikely, but possible.Quote: AyecarumbaWhat if prisoner #11 gets picked 18 times in a row?
Quote: ThatDonGuyI assume you're referring to my answer?
The answer to the first one is, he doesn't have to know. If it's down, he leaves it alone, and moves the other switch. Whether it was down from the beginning or someone else moved it down is irrelevant. That's why the counter has to count to 44 instead of just 22.
The answer to the second one is, it's the same as if he was the first to enter the room on day 1, or day 19, or day 256. The counter has no way of knowing whether or not anyone has entered the room and moved Switch A - and remember that both "the counter is the first to enter" and "Switch A was down from from the beginning" are both possible.
If you know the first day on which someone will definitely enter the room, the solution becomes, everybody who enters before that day moves switch B, and then it becomes your solution to the original problem.
Then it's going to take longer for them to get freed. It's possible that all of them could die before all of them enter the room - very, very unlikely, but possible.
If one of the prisoners dies, then the rest would likely be stuck in prison forever. Unless for some reason, the warden would call on a dead guy to enter the switch room.
I'm still a little weary of your solution, TDG, but my brain's a little mushy right now to try to prove or disprove it.
PS I assume the problem is (sorry if I misunderstood).
Switches are initially set at random but identified with "A" and "B" and can be "Up" or "Down" (or On and Off if you prefer).
The game starts on a specific day known to all.
Prior to start people can discuss any method, but they are never in contact with each other once the game has started.
Every day someone picked at random will go in room and must alter one and only one of the switches.
People are allowed to remember their own history and can reliably count days, remember how the switches were etc.
When anyone knows for certain that all 23 people have been in the room then they can stop the game.
I see some discussion about some days people aren't chosen - in this case I can't currently see a solution.
548.845
I assume everyone is happy with using A as a toggle and B as the information switch. The first one in ensures the switch is up either by flipping B or, if it's already correct, flipping A. Hereafter A B and C refer to people going in on 1st thru 3rd days. The problem is how does someone going in first time on the third day know whether one (AA) or two (AB) people have already been in.
Essentially the one who goes in on the 3rd day is counter - most the time it is three different persons so the counting can start by only looking for 20 people.
Simple solution - counter is first one in who sets switch up.
Everyone else if they find switch up and haven't yet set it down previously, set it down, else leave it.
Counter - if find switch down, count how many, set it up. If count implies everyone been in "scream".
After a switch has been set It takes 23 turns before counter is chosen
After a reset it takes 23/(number of people to go) to find someone new to set switch
Add one for the first turn which selects counter.
19 to go 24.21052632 518.5980121
20 to go 24.15 542.7480121
21 to go 24.0952381 566.8432502
22 to go 24.04545455 590.8887048
Better solution A sets switch up, B sets switch down, C sets switch up. Whoever goes in on 3rd day is counter.
A knows scenario (i), B knows scenario (ii), B tells scenario (iii) as A left switch up so knows it was AAx, C tells scenario (iv) as B left switch down so knows it was ABx
A A A 1.11699188 1/23 1/23 * f(22) 0.189%
A B B 23.57382137 22/23 1/23 * f(21) 4.159%
A A B 23.57382137 1/23 22/23 * f(21) 4.159%
A B A 23.57382137 1/23 22/23 * f(21) 4.159%
A B C 474.0067705 22/23 21/23 * f(20) 87.335%
first three turns 3 plus the three turns to set it up
548.8452265 100.000%
So what happens if, in the Wizard's version of the problem, one of the prisoners dies before ever having entered the room?Quote: RSIf one of the prisoners dies, then the rest would likely be stuck in prison forever. Unless for some reason, the warden would call on a dead guy to enter the switch room.
Quote: charliepatrick
548.845
I assume everyone is happy with using A as a toggle and B as the information switch. The first one in ensures the switch is up either by flipping B or, if it's already correct, flipping A. Hereafter A B and C refer to people going in on 1st thru 3rd days. The problem is how does someone going in first time on the third day know whether one (AA) or two (AB) people have already been in.
Essentially the one who goes in on the 3rd day is counter - most the time it is three different persons so the counting can start by only looking for 20 people.
Simple solution - counter is first one in who sets switch up.
Everyone else if they find switch up and haven't yet set it down previously, set it down, else leave it.
Counter - if find switch down, count how many, set it up. If count implies everyone been in "scream".
After a switch has been set It takes 23 turns before counter is chosen
After a reset it takes 23/(number of people to go) to find someone new to set switch
Add one for the first turn which selects counter.
19 to go 24.21052632 518.5980121
20 to go 24.15 542.7480121
21 to go 24.0952381 566.8432502
22 to go 24.04545455 590.8887048
Better solution A sets switch up, B sets switch down, C sets switch up. Whoever goes in on 3rd day is counter.
A knows scenario (i), B knows scenario (ii), B tells scenario (iii) as A left switch up so knows it was AAx, C tells scenario (iv) as B left switch down so knows it was ABx
A A A 1.11699188 1/23 1/23 * f(22) 0.189%
A B B 23.57382137 22/23 1/23 * f(21) 4.159%
A A B 23.57382137 1/23 22/23 * f(21) 4.159%
A B A 23.57382137 1/23 22/23 * f(21) 4.159%
A B C 474.0067705 22/23 21/23 * f(20) 87.335%
first three turns 3 plus the three turns to set it up
548.8452265 100.000%
Charlie, in your solution, what happens if the same person is called twice or all three times in the first three days?
Quote: ThatDonGuySo what happens if, in the Wizard's version of the problem, one of the prisoners dies before ever having entered the room?
Then the dead guy just screwed all his fellow prisoners. He's gotta be a team player.
From A's viewpoint
AAA: If A is called on all three days: firstly he knows this and so can leave the switch up and start counting, but then has to wait for everyone else (f22).
AAB: A knows he went in on days 1 and 2 but not day 3, so knows he's not the counter but that someone else (B) has taken this role. A also knows he's already "been counted".
ABA: A knows he went in on days 1 and 3 so knows he's become the counter and that someone else (B) has already been counted. A also, knows B is assuming he's already "been counted", so now has to wait for everyone else except B (f21).
Axx: A knows he only went in on day 1, so knows he's not the counter but whomever went in on day 3 has become the counter and will have already counted A.
From C's viewpoint - or the person who only goes in on day 3
ABC: or "AAC": The person who goes in on day 3 knows he hasn't been in before but needs to know whether the two previous days were AA or AB. This can be determined by the position of the switch. In AAC the switch will be up, in ABC the switch will be down. C becomes the counter and now knows how many people are left to count, either everyone except A (f21) or everyone except A and B (f20).
From B's viewpoint
AAB: This is "AAC" above, where the person knows he's not been in on days 1 or 2 but then finds out A went in on days 1 and 2 (f21).
ABB: B knows he went in on both 2nd and 3rd days. So resets the switch up and knows to count everyone except A (f21).
ABC or ABA: B knows he didn't go in on day 3 but will have already been counted by either A or C.
Quote: charliepatrickI am assuming people have memory and can remember whether they've been in the room before and in particular whether they've been in yesterday or the day before that. By the end of the third day the people involved will then know whether they are the counter (the person who goes in on the 3rd day becomes counter) or have already been counted (if they only go in on the 1st and/or 2nd day).
From A's viewpoint
AAA: If A is called on all three days: firstly he knows this and so can leave the switch up and start counting, but then has to wait for everyone else (f22).
AAB: A knows he went in on days 1 and 2 but not day 3, so knows he's not the counter but that someone else (B) has taken this role. A also knows he's already "been counted".
ABA: A knows he went in on days 1 and 3 so knows he's become the counter and that someone else (B) has already been counted. A also, knows B is assuming he's already "been counted", so now has to wait for everyone else except B (f21).
Axx: A knows he only went in on day 1, so knows he's not the counter but whomever went in on day 3 has become the counter and will have already counted A.
From C's viewpoint - or the person who only goes in on day 3
ABC: or "AAC": The person who goes in on day 3 knows he hasn't been in before but needs to know whether the two previous days were AA or AB. This can be determined by the position of the switch. In AAC the switch will be up, in ABC the switch will be down. C becomes the counter and now knows how many people are left to count, either everyone except A (f21) or everyone except A and B (f20).
From B's viewpoint
AAB: This is "AAC" above, where the person knows he's not been in on days 1 or 2 but then finds out A went in on days 1 and 2 (f21).
ABB: B knows he went in on both 2nd and 3rd days. So resets the switch up and knows to count everyone except A (f21).
ABC or ABA: B knows he didn't go in on day 3 but will have already been counted by either A or C.
Remember, these are prisoners, not rocket scientists!