Skip to content

Instantly share code, notes, and snippets.

@furnox
Created April 25, 2020 17:26
Show Gist options
  • Save furnox/4c0a3757c43aafad489d1e31bd4e80f8 to your computer and use it in GitHub Desktop.
Save furnox/4c0a3757c43aafad489d1e31bd4e80f8 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
results = {}
def stats(num):
if num in results:
return results[num]
if num == 1:
return 0
if num % 2 == 0:
hops = stats(num // 2) + 1
results[num] = hops
return hops
else:
hops = stats(num * 3 + 1) + 1
results[num] = hops
return hops
for i in range(1000000, 1, -1):
stats(i)
mymax = max(results, key=lambda key: results[key])
print(mymax, ' has the most hops: ', results[mymax])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment