Two Egg problem:
- You are given 2 eggs.
- You have access to a 100-storey building.
- Eggs can be very hard or very fragile means it may break if dropped
from the first floor or may not even break if dropped from 100 th
floor.Both eggs are identical.
- You need to figure out the highest floor of a 100-storey building an egg can be dropped without breaking.
- Now the question is how many drops you need to make. You are allowed to break 2 eggs in the process
For an optimal solution, if the first segment is of size N, then the
second has to be of size N-1, and so on (because when you start testing
the second segment, you've already dropped the egg once for the first
segment).
So you need to solve
n+(n-1)+(n-2)+...+1<=100
, from where
(n)(n+1)/2<=100
(this function transform is done with arithmetic series aka sum of an arithmetic sequence), now if you solve for n (wolframalpha:
Reduce[Floor[n + n^2] >= 200, n]
) you get 14. Now you know that the first floor where you need to make
the drop is 14th floor, next will be (14+14-1)th floor and whole
sequence:
14; 27; 39; 50; 60; 69; 77; 84; 90; 95; 99; 100
If you break the first egg, you go back to the last one and linearly
check all options until you break the second egg, when you do, you got
your answer. There is no magic.
No comments:
Post a Comment