A version of light-switching problem goes like this: N prisoners will be separated from each other without communication. They will be selected one at a time at random to enter a room with a switch. The only thing they can do while staying there is to move the switch if they like, and then they will leave the room no matter what. The process goes on and on indefinitely. If at some point anyone of them can ascertain that all of them have entered the room at least once, and it's true, then they'll all be freed. The initial state of the switch is unknown. Given a sufficiently long period of time each of them will enter the room as many times as they wish. Now, they can meet once before the process starts to figure out a strategy that guarantees their freedom at some point in the future!
Scroll down for solution...
A more common solution is to assign a counter among them before hand. The counter only turns off the switch when it's on, and counts the number of time he/she does so. The rest turns the switch on when it's off. Each of them does so 2 times to counter the fact that the initial state of the switch is unknown. When the counter counts 2N-2 times, he/she knows everyone else has been to the room.
Interestingly, there's an alternative solution without having the counter counts to 2N-2. It is posted here. Below is my explanation/proof that it works.
The only changes of status of the switch are made by the counter, who does so every time, and by the rest switching it off when transitioning from READY or WAITING mode to DONE mode, as depicted in the solution strategy. Because these non-counter moves all turn the switch off, there will never be multiple of them between counter's moves. So the counter will only counts to at most N-1. Now why is this solution robust to the unknown initial state of the switch? It suffices to show that every such non-counter move will be counted by the counter. Why? Because every non-counter only turns the switch off when in READY mode, and yet they only enters READY mode when they observe the state change of the switch. Thus, the first ever move of the switch must be made by the counter, so he/she will capture every non-counter move without any uncertainty as opposed in the common solution due to the unknown initial state. Finally, the counters moves the switch everytime to make sure that all the rest will be triggered to transition from the initial WAITING mode to READY mode.
No comments:
Post a Comment