Your challenge:
You are on the 0th floor of a infinitely tall building. At any floor, you can walk to the window and drop an egg. Your goal is to figure out the highest floor that the egg can withstand without breaking. However, you have a maximum of 3 eggs to use to figure this out, but you need to minimize the number of tries.
In formal terms:
- You are given a function
f(n)
which returnsbool(n <= X)
for an unknownX
, where0 <= X
- You must return the value of
X
(without accessing it directly) f(n)
must only returnFalse
a maximum of3
times (in a single test case). If it returnsFalse
more than that, then your answer is disqualified.
Restrictions
Your score is the total number of calls you make to f(n)
(in the test cases below)
If you wish, you may forgo passing in a function, and simply "simulate" the above situation. However, your solving algorithm must know nothing of X
.
Your algorithm should not hard code the test cases, or a maximum X
. If I were to regenerate the numbers, or add more, your program should be able to handle them (with a similar score).
If your language doesn't support arbitrary precision integers, then you may use the long
datatype. If your language doesn't support either, then you are out of luck.
The nth test case is generated using the following:
g(n) = max(g(n-1)*random(1,1.5), n+1), g(0) = 0
, or approximately 1.25^n
Test cases:
0,1,2,3,4,6,7,8,10,14,15,18,20,27,29,40,57,61,91,104,133,194,233,308,425,530,735,1057,1308,1874,2576,3162,3769,3804,4872,6309,7731,11167,11476,15223,15603,16034,22761,29204,35268,42481,56238,68723,83062,95681,113965,152145,202644,287964,335302,376279,466202,475558,666030,743517,782403,903170,1078242,1435682,1856036,2373214,3283373,4545125,6215594,7309899,7848365,8096538,10409246,15103057,20271921,22186329,23602446,32341327,33354300,46852754,65157555,93637992,107681394,152487773,181996529,225801707,324194358,435824227,579337939,600264328,827690923,1129093889,1260597310,1473972478,1952345052,1977336057,2512749509,3278750235,3747691805,5146052509
This is a code-challenge, and the person with the lowest score wins!