A building has 100 floors. Somewhere there is a lowest floor from which an egg breaks when dropped: from any floor below an egg survives, and from or above it breaks. You do not know , and it could be any floor from 1 to 100. You have 2 identical eggs. A broken egg is gone, and an egg that survives can be dropped again. You want to find exactly. What is the fewest drops that is guaranteed to be enough, whatever turns out to be?
The count that matters is the worst case: the strategy is judged by the unluckiest .
Bisection is the right idea with unlimited eggs, and with two it fails. Drop from floor 50. If the egg breaks you have one egg left, and is between 1 and 50, and the only safe way to search with a single egg is to go up one floor at a time from the bottom: 1, 2, 3 and so on. In the worst case, or , that is 1 + 49 = 50 drops. The script runs bisection with this fallback for every and finds the worst case is 50, first reached at .
Drop from 10, 20, 30 and so on up to 100. When an egg breaks, you walk up the last block one floor at a time with the other egg. The worst case is a top block: ten drops to get there, and then nine more to walk, 91 to 99. That is 19. The cost is not even. If the egg breaks at the first block you spend about ten drops, and at the top block, nineteen. The unlucky cases are much more expensive than the lucky ones, and that unevenness is waste.
Suppose the worst case is to be drops. Drop first from floor . If the egg breaks you have one egg and floors 1 to to walk, so drops: right on budget. If it survives, you have spent one drop and have left, so the next jump can be floors, to floor . If that egg breaks, you have used two drops and walk floors, again . Each time you survive, you have one fewer drop, so each jump is one floor shorter, and every way the egg can break costs exactly .
The jumps are , and together they reach floor
We need this to be at least 100. With it is 91, which is too small, and with it is 105, which is enough. So .
The jump sizes are 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1. Adding them up gives the floors 14, 27, 39, 50, 60, 69, 77, 84, 90, 95, 99, 102, 104, 105. The ladder is 105 high and the building is only 100, so the film caps it at 100: the floors dropped from are 14, 27, 39, 50, 60, 69, 77, 84, 90, 95, 99, 100.
Here is each rung of the ladder, and the worst case if the egg breaks there:
| drop from | jump | drops so far | floors to walk | total if it breaks here |
|---|---|---|---|---|
| 14 | 14 | 1 | 13 | 14 |
| 27 | 13 | 2 | 12 | 14 |
| 39 | 12 | 3 | 11 | 14 |
| 50 | 11 | 4 | 10 | 14 |
| 60 | 10 | 5 | 9 | 14 |
| 69 | 9 | 6 | 8 | 14 |
| 77 | 8 | 7 | 7 | 14 |
| 84 | 7 | 8 | 6 | 14 |
| 90 | 6 | 9 | 5 | 14 |
| 95 | 5 | 10 | 4 | 14 |
| 99 | 4 | 11 | 3 | 14 |
| 100 | 1 | 12 | 0 | 12 |
Every worst case is at most 14. The last rung, floor 100, is cheaper because the ladder was cut off at the top. The script runs the ladder for every one of the 100 possible values of , checks that it finds each time, and the most drops any of them needs is 14.
Let be the most floors you can search with drops and eggs, so that you are sure to find . Drop an egg from some floor.
So the most you can cover is
and no strategy can cover more than this, because each drop gives only two answers. With one egg, you can only walk up, so . With two eggs the recurrence gives , so , which adds up to . This is the ladder's triangle. The script checks the formula for every from 1 to 30.
For 100 floors we need the smallest with . That is , because . So 14 is the best possible, by the recurrence and not only by the ladder.
Other heights. The same count works for any building. The script checks it for three heights:
| floors | fewest drops with two eggs |
|---|---|
| 10 | 4 |
| 50 | 10 |
| 100 | 14 |
| 200 | 20 |
More eggs. With three eggs, 100 floors need 9 drops, and with four eggs, 8. Each extra egg lets you search a coarser grid with the first drops, with a second egg to back it up.
scripts/two-eggs.mjs asserts the claims below before it writes maths.json, and its --check fails if the file is stale. It checks that:
4 drops. The triangular number 10 is , so the first drop is from floor 4, then 7, then 9, then 10.
Four drops have been used, at 14, 27, 39 and 50. Floors up to 39 are safe, so is between 40 and 50, and the second egg walks up from 40: floors 40 to 49, at most ten more drops. The worst case is 4 + 10 = 14, which is the budget; the table above shows it on the row for floor 50.
A drop at 50 that breaks leaves 49 floors to walk with one egg, which costs 50 drops in all. A drop at 14 that breaks leaves only 13 floors to walk, which costs 14 drops in all. The ladder is built so that every break costs the same.