Skip to content

Commit ec6893c

Browse files
committed
add "prisoners and a light bulb" riddle
1 parent c4aa30b commit ec6893c

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

riddles/bulb.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Prisoners and a light bulb
2+
==========================
3+
4+
A prison guard is giving 100 prisoners a second chance for their death
5+
sentences. The guard tells them that everyday, starting from tomorrow, he will
6+
pick one prisoner randomly from his cell and bring him to his office. In the
7+
office there is a light bulb wired to a power switch. The light bulb is
8+
initially off and only has two states, on or off, triggered by the power
9+
switch. While the prisoner is in the office, he has to do one of the following
10+
things here: either _flip the power switch_ of the light bulb, and thus altering
11+
its state (if it is off, this turns it on, and vice versa), or do
12+
_nothing_. After the prisoner has chosen his action, he is brought back to his
13+
cell and locked up. The process is then repeated the next day with another
14+
random prisoner (it could be the same one, since the pick is random).
15+
16+
Now, if any prisoner, that is currently in the office, knows for certain that
17+
every other prisoner has been in the office at least once, he can tell that to
18+
the guard. If his claim is true, they are all spared, otherwise the game is over
19+
and they all get killed!
20+
21+
The guard is a very patient man and has thus no time limit for his little
22+
game. He will continue bringing a random prisoner to his office every day, until
23+
some one dares to make the claim. His random pick is [uniformly
24+
distributed](https://en.wikipedia.org/wiki/Uniform_distribution_(continuous)),
25+
meaning that every prisoner has the _exact_ same probability to be picked
26+
(1/100). Moreover, each one of the prisoners is contained in a different
27+
isolated cell. There are no ways for them to communicate with each other at
28+
all. They can also not leave any kind of "message" in the office for the others;
29+
the guard only lets them flip the power switch for the bulb or do nothing.
30+
31+
The guard lets the prisoner discuss a strategy for a short period of time before
32+
locking them in their respective cells for tomorrow's game. What is a winning
33+
strategy for the prisoners, that spares them from their death sentences?
34+
35+
**[Solution](../solutions/bulb_solution.md)**

solutions/bulb_solution.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Solution to prisoners and a light bulb
2+
======================================
3+
4+
One prisoner is assigned as a _counter_. The role of this counter is to keep
5+
track of how many prisoners that have entered the office. The counter thus has
6+
to count 99 other prisoners before he can tell the guard.
7+
8+
Now, when one of the other 99 prisoners enters the office and the light bulb is
9+
on, he does nothing. If it is off, he turns it on but and only if he has not
10+
done this before. When the counter enters the room and sees the bulb on, he
11+
switches it off and increments his count with one. Since prisoners only switches
12+
the light bulb on if they have not done this before, the switched on light bulb
13+
encountered by the counter is a different unique prisoner. Thus, after the
14+
counter has switched the light bulb off 99 times he can now tell the guard that
15+
every prisoner has entered the office.
16+
17+
**Remark**: This solution, for 100 prisoners, has an expected run time of
18+
10417.74 days (28.54 years). There are more complex and efficient
19+
solutions. However, the question of optimality is still open. For more details
20+
please see this
21+
[paper](https://www.ocf.berkeley.edu/~wwu/papers/100prisonersLightBulb.pdf).

0 commit comments

Comments
 (0)