Skip to content

Instantly share code, notes, and snippets.

@mrjohannchang
Last active August 29, 2015 13:59
Show Gist options
  • Save mrjohannchang/11000240 to your computer and use it in GitHub Desktop.
Save mrjohannchang/11000240 to your computer and use it in GitHub Desktop.
Two Eggs Problem
n = int(input())
t = [0] * (n + 1)
def find_min_test(x, t):
if x < 3:
t[x] = x
return x
if t[x]:
return t[x]
t[x] = min(max(i, 1 + find_min_test(x - i, t)) for i in range(1, x + 1))
return t[x]
for i in range(1, n + 1):
find_min_test(i, t)
print(find_min_test(n, t))
for i in range(1, n):
if i * (i + 1) >= 2 * n:
print(i)
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment