Last active
March 24, 2016 18:41
-
-
Save renyi/3b63b3998a1800ac6a51 to your computer and use it in GitHub Desktop.
This file contains 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/env pypy | |
import time | |
n = 13 | |
# n = 1000000 | |
if __name__ == "__main__": | |
def calc(n): | |
global g_max | |
g_max += 1 | |
if n == 1: | |
return 1 | |
elif n % 2 == 0: | |
return calc(n/2) | |
else: | |
return calc(3*n + 1) | |
start = time.time() | |
max_x = 0 | |
max_count = 0 | |
for x in xrange(n, 1, -1): | |
g_max = 0 | |
calc(x) | |
if g_max > max_count: | |
max_x = x | |
max_count = g_max | |
print max_x, max_count | |
end = time.time() | |
print end-start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment