Created
December 15, 2014 11:44
-
-
Save zemlanin/4b1c1d02ab138cea9c7b to your computer and use it in GitHub Desktop.
euler14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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