Skip to content

Instantly share code, notes, and snippets.

@zemlanin
Created December 15, 2014 11:44
Show Gist options
  • Save zemlanin/4b1c1d02ab138cea9c7b to your computer and use it in GitHub Desktop.
Save zemlanin/4b1c1d02ab138cea9c7b to your computer and use it in GitHub Desktop.
euler14
# extra short
M=k=L=0
while k<1e6:
n=k=k+1;l=1
while n>1:n=[n/2,3*n+1][n%2];l+=1
if l>L:M,L=k,l
print M
# short and fast
r={1:1};k=L=M=0
while k<1e6:
n=k=k+1;l=0
while n not in r:n=[n/2,3*n+1][n%2];l+=1
r[k]=l=l+r[n]
if l>L:M,L=k,l
print M
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment