Light bulbs
Once upon a time, my CTO challenged me for a fun problem of bulbs described below:
You have two light bulbs (or eggs) and a 100 storey building. You must determine the minimal floor such that if you drop the light bulb from that floor it breaks. Once you break a bulb, it can’t be reused.
Question 1: What’s the smallest number of drops required in the WORST case to determine the minimal floor.
The solution is well explained by Craig Mason-Jone here, or you can easily google it. Briefly assuming the minimal number of drops is , first you drop the bulb at floor
. If it breaks, you try to drop the second bulb from floor 1 to floor
– 1. If the first bulb doesn’t break at floor
, you can try to drop it at floor
– 1. If it breaks at
-1, then try to drop the second bulb from floor
+ 1 to
. It breaks down to find
such that:
It turns out is the optimal solution (examined by computer).
Question 2: But what if we have 3 bulbs ?
Similarly we assume that the minimal number of drops in the worst case is . We know that with 2 bulbs and
– 1 drops the maximum number of floors we can examine is
. Hence the first drop will be at floor
. If the bulb breaks, examine the floors from 1 to
with 2 bulbs like mentioned above. If it doesn’t break, we now have
– 1 drops left. Thus the second drop is at floor
. Similarly we need to find
such that:
Question 3: What if we have
bulbs and
floors ?
We can follow the method as in question 2 or compute a function where:
This can be explained as if we drop a bulb at floor and the bulb breaks,
else
; And the worst case is the larger in two. The solution is then to find
where
is minimum.
Question 4: What if we have an infinite number of bulbs ?
The function becomes:
We know that:
Therefore: