Created
April 25, 2020 17:26
-
-
Save furnox/4c0a3757c43aafad489d1e31bd4e80f8 to your computer and use it in GitHub Desktop.
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
#!/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