You are given just 6 eggs, and access to a 35-storey building. All 6 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.
Adopting an optimal strategy what is the absolute minimum number of egg drops you need to reach the solution given any and every possible scenario?
Details and Assumptions :
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
the easiest way to solve this one is by a binary method. the eggs can have 2 states, not broken (0) and broken (1). we have a total of 6 eggs to test, with chances to repeat it in case of a 0. our worst case is that the six eggs broke, a string of 111111.
this binary value into a base 10 equals 63.
if we check with 5 drops, our worst case (11111) only covers a maximum of 31 levels.
since 63 > 35, it ensures that we will need a maximum of 6 to know the floor we are searching for
1)first drop goes to floor 32,
IF
it breaks we divide the amount (go to floor 16) and test again, (A LOOP)
ELSE
if it doesnt we add half the amount and test again (another loop)
(floor 48, it doesnt exist so we consider it a value of 0 and repeat the previous condition untill we find a level that exist) // a condition for the maximum level