Problem. prisoners; each day one is chosen uniformly at random and visits a room with a light bulb (initially off) that they may toggle. At any time a prisoner may declare that everyone has visited; if wrong, all lose. They may agree on a strategy beforehand.
Counter strategy: one prisoner is the counter. Every other prisoner turns the light on the first time they find it off (and never again); the counter turns it off whenever it is on and counts. When the count reaches , the counter declares, and the declaration is always correct.
double bulbExpectedDays(int n) { // counter strategy: phases alternate "new pirate switches on" and "counter visits"
double e = 0;
for (int i = 0; i < n - 1; i++) e += (double)n / (n - 1 - i) + n;
return e;
}| expected days (counter strategy) | |
|---|---|
| 8 | about 77 |
| 100 | about 10418 (28.5 years) |
Proof: correctness and expected time
Correctness. Each non-counter switches the light on at most once, and only after visiting; the counter switches it off and counts each such event exactly once (the light is never turned on twice before the counter sees it, because others only turn it on when it is off). So a count of proves that all others visited, and the counter visited too. Time. The process alternates: with prisoners counted and the light off, wait for a new non-counter prisoner (probability per day, mean ), then for the counter (probability , mean ). Summing over gives . Checked against simulation for . Faster strategies (rounds with several counters) reduce the expected time to a few thousand days for .