Skip to content

Instantly share code, notes, and snippets.

@renyi
Last active March 24, 2016 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renyi/3b63b3998a1800ac6a51 to your computer and use it in GitHub Desktop.
Save renyi/3b63b3998a1800ac6a51 to your computer and use it in GitHub Desktop.
#!/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