Egg Dropping
For a school project, you’ve devised an egg-protection device — a little contraption that wraps around an egg and is supposed to keep it from breaking when dropped from a height. You’ve built two prototypes and now you need to figure out just how effective they are.
Near your school is a 100-storey building. The device might fail from as low as the first floor, or it might protect the egg all the way from the 100th — you have no idea. You need to find the “break floor” — the lowest floor from which a protected egg will still break on impact. Note that the device may survive even a drop from the 100th floor, in which case there is no break floor.
What is the minimum number of drops you’d ever need in the worst case to determine the break floor? You’re allowed to break both eggs, as long as you can identify the correct floor afterwards.
Hint 1
Experiment with simpler versions of the problem. Perhaps you can try a shorter building, or you can try having only 1 device instead of 2.
Hint 2
If you only had 1 device, you cannot do better than 100 drops in the worst case. Why?
Solution
Let’s start from the beginning. If you dropped the device from the 2nd floor and it broke, you know the break floor is either 1 or 2, but you don’t have any devices left to test. The same goes for any floor above the 2nd floor.
This means you have to test the 1st floor, then the 2nd floor, and so on; all the way up to the 100th floor. In the worst case, the device doesn’t break at all, and you’d have to test the drop from all 100 floors.
Now consider what happens when you have 2 devices.
Hint 3
If your first move is to drop from the 50th floor, what’s the minimum number of drops you’d have to do in the worst case scenario?
Solution
You would have to do 50 drops in the worst case scenario.
Case 1: If the device breaks at the 50th floor, we’re now left with 1 device to test the remaining floors 1 to 49. That’s a total of 49 drops + the first drop for a total of 50.
Case 2: If the device doesn’t break at the 50th floor, we can drop the device once more on any floor in the middle, so let’s go with the 75th floor. If it breaks, we can test floors 51 to 74 for a total of 26 drops in the worst case. If it doesn’t break, we can still test the remaining 25 floors with a naive brute force solution and still come up with 27 drops in total. Either way, you cannot do as bad as the 50 drops required in case 1.
Solution
Answer: 14 drops.
Let’s work our way up to a solution. As we’ve seen from the hints, once the device has broken, you will need to brute force ALL the remaining floors in the worst case scenario. But how do we optimise this then?
First, let’s start with a simpler version of the problem with 6 floors and 2 devices. We’ll start with a naive solution for now:
- First drop: Drop from floor 3.
- If it breaks, test floor 1, then 2. Worst case: 3 moves.
- If it doesn’t break, drop from floor 6.
- If it breaks, test floor 4, then 5. Worst case: 4 moves.
- If it doesn’t break, then we know the device survives all 6 floors.
This gives us a worst case of 4 moves.
Let’s come up with a way to visualise this. We indicate the drops with device 1 on a horizontal line. We start from the left point, and each step to the right indicates a drop.
When the device breaks on a specific floor, we can no longer make a horizontal step, so we must now take vertical steps downward. From hint 2, we know that once we’re left with 1 device, we must test all the floors sequentially. If the device breaks at floor 3, we need to test floors 1 and 2. If the device breaks at floor 6, we need to test floors 4 and 5. This gives us the following diagram:
We can see from this diagram that we have a worst-case of 4 moves (Start → 3 → 6 → 4 → 5). Can we do better? Let’s try a different strategy:
- First drop: Drop from floor 2.
- If it breaks, test floor 1. Worst case: 2 moves.
- If it doesn’t break, drop from floor 4.
- If it breaks, test floor 3. Worst case: 3 moves.
- If it doesn’t break, test floor 6.
- If it breaks, test floor 5. Worst case: 4 moves
- If it doesn’t break, then we know the device survives all 6 floors.
Hmm, we’re still stuck with a worst-case of 4 moves (Start → 2 → 4 → 6 → 5). But does that mean we’ve found the optimal number of drops?
No! Notice how in both versions of the diagram, we have short paths that terminate early. In version 1, we have (Start → 3 → 1 → 2) and (Start → 3 → 6 without breaking). In version 2, we have (Start → 2 → 1), (Start → 2 → 4 → 3), and (Start → 2 → 4 → 6 without breaking). If we could make these longer in order to shorten the worst-case path, we’ll find a better solution. And in fact, we can!
- First drop: Drop from floor 3.
- If it breaks, test floor 1, then 2. Worst case: 3 moves.
- If it doesn’t break, drop from floor 5.
- If it breaks, test floor 4. Worst case: 3 moves.
- If it doesn’t break, test floor 6. Worst case: 3 moves.
No matter which path we take, we’ll always end up with 3 moves in the worst case.
With this visualisation in mind, let’s explore some solutions for the 100-storey version of the puzzle. In hint 3, we offered a naive solution of dropping from the 50th floor. Visualising it with our new diagram, it looks like this:
Oof, that’s rough. It seems like we’re not taking proper advantage of the first device (the rightward movement on the diagram). So instead of making such huge jumps with the first device, we should instead move it in smaller steps.
How about steps of 10? This time, we’ll try dropping the first device from floor 10, then 20, then 30, and so on. At the first floor that it breaks on, we will test the remaining floors in between the last 2 drops. For example, if the first device breaks on floor 60, then we will drop the second device from floor 51, 52, ..., 59. Our diagram now looks like this:
In the worst case scenario, we have 19 moves (Start → 10 → 20 → 30 → 40 → 50 → 60 → 70 → 80 → 90 → 100 → 91 → 92 → 93 → 94 → 95 → 96 → 97 → 98 → 99). But notice how the shorter chains have only 10 moves, 11 moves, and so on? Let’s lengthen them. Instead of having the first drop at 10, we can have the first drop at 14 (a jump of 14). Then our next jump should be 14+13=27. Then the following drop should be 27+12=39. Continuing this way, we get a chart of:
In the worst case scenario, we have 14 moves, and we can’t do any better than this. However, through this diagram, we see that for a maximum of 14 moves, this strategy works up to a maximum building height of 105 storeys.
Now that you’ve found the optimal strategy for 2 devices and 100 storeys, try to generalise:
- For 2 devices, what is the minimum worst-case number of drops for a building of n storeys?
- For 2 devices, what is the maximum building height coverable with at most k drops in the worst case?
- For d devices and an n-storey building, what is the minimum worst-case number of drops?
Try These Next
Chain Link 2
An apprentice is working for you, the village’s master blacksmith, for 21 days. For payment, you have agreed to give him a gold chain with 21 links, one link...
Two-Bullet Russian Roulette
After offending the toughest guy, Big Billy, at the saloon, he challenges you to a game of Russian Roulette. He takes out a revolver with 6 chambers and loads...
Watermelons Drying in The Sun
A farmer is proud of his newest feat: growing a 120 kg watermelon that he wants to enter in the farming contest next week. Using a special sensor, he detects...