[Math] Eggs and Floors Puzzle – Extended & Generalized

algorithmsdynamic programming

I asked this question on the CS exchange, and some have mentioned that this is more of a math problem than a CS problem. Thus, I will proceed to ask it here:

Recently I've run across the "Two eggs, 100 floors" problem:

You are given two eggs, and access to a 100-story building. Both eggs are identical. The aim is to find out the highest floor from which an egg will not break when dropped out of a window from that floor. If an egg is dropped and does not break, it is undamaged and can be dropped again. However, once an egg is broken, that’s it for that egg.

If an egg breaks when dropped from floor n, then it would also have broken from any floor above that. If an egg survives a fall, then it will survive any fall shorter than that.

This page (http://datagenetics.com/blog/july22012/index.html) explains how to solve this puzzle very well, but I've run across an extension that asks for an algorithm for what floor to drop the first egg from.

When considering this for the 2 eggs, 100 floors problem, I found that the first floor to throw the egg from (14) matched the minimum number of throws required to find the floor for which the egg doesn't break from when thrown.

However, when extending this to 3 eggs, the total number of throws needed becomes 9, but that doesn't mean that the FIRST egg throw needs to be made from the 9th floor. Intuitively, it would need to be from a higher floor than 14.

Thus, my question is not "how do you minimize the number of throws" as the original puzzle states. My question is: How do you determine what floor to drop the FIRST egg from when you have n eggs and k floors? Is it possible to find a generalized approach for that?

I've had some comments explain that the algorithm on the link included can be extended to include where to throw the first egg from. I need help explaining how that can be done.

Best Answer

For three eggs and 100 floors, the sequence of steps can be as follows: 37, 66, 88, 100. In the event that at the first throw the first egg is broken, then we have 2 eggs and 36 suspicious floors at our disposal. 36 floors are checked for 8 steps by two eggs. If on the 37th floor the egg survived, and on 66 it broke, then there are 28 suspicious floors and 2 eggs. For them, there will be enough 7 steps. If on the 66th floor the egg survived, and on 88 it broke, then there are 21 suspicious floors and 2 eggs. For them, there will be enough 6 steps. And, finally, a throw from the 100th floor. There altogether there are 11 suspicious floors for which there will be enough 5 attempts. So, in each case there will be enough 9 shots.

https://docs.google.com/spreadsheets/d/1qxmhZCHj2aVMiND_pC3XUFnj_v8oQmZ-t9h4dHXl_GQ/edit?usp=sharing

In the table above I use dynamic (recurent) formula $floor(eggs, drops)=floor(eggs-1, drops-1)+floor(eggs, drops-1)+1$

Related Question