Skip to content

Instantly share code, notes, and snippets.

@angch
Last active March 25, 2016 04:24
Show Gist options
  • Save angch/77e99539f7fde179a168 to your computer and use it in GitHub Desktop.
Save angch/77e99539f7fde179a168 to your computer and use it in GitHub Desktop.
terms = [None] * 1000001
maxterms = 0
maxtermsNum = 0
for i in range(1,1000001):
c = i
count = 1
while c > 1:
if c % 2 == 0:
c = c / 2
else:
c = c * 3 + 1
if c < i:
count = count + terms[c]
break
count = count + 1
terms[i] = count
if count > maxterms:
maxterms = count
maxtermsNum = i
print maxtermsNum, maxterms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment