Skip to content

Instantly share code, notes, and snippets.

@david-batranu
Created October 23, 2013 11:27
Show Gist options
  • Save david-batranu/7116897 to your computer and use it in GitHub Desktop.
Save david-batranu/7116897 to your computer and use it in GitHub Desktop.
collatz = {1:1}
def Collatz(n):
global collatz
if not collatz.has_key(n):
if n%2 == 0:
collatz[n] = Collatz(n/2) + 1
else:
collatz[n] = Collatz(3*n + 1) + 1
return collatz[n]
for j in range(1000000,0,-1):
Collatz(j)
print collatz.keys()[collatz.values().index(max(collatz.values()))]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment