Mucho mejor.
Código Python:
Ver originaldef max_cycle(a, b):
cache = {1:1}
def num(cache, n):
if not n in cache:
if n % 2:
cache[n] = 1 + num(cache, 3 * n + 1)
else:
cache[n] = 1 + num(cache, n / 2)
return cache[n]
def sec(a, b):
maxim = 0
if a > b: a,b = b,a
for i in xrange(a, b+1):
tr = num(cache, i)
if tr > maxim:
maxim = tr
return maxim
return sec(a, b)
if __name__ == '__main__':
from time import time
t1 = time()
assert max_cycle(1, 10) == 20
assert max_cycle(100, 200) == 125
assert max_cycle(201, 210) == 89
assert max_cycle(900, 1000) == 174
assert max_cycle(113383, 113383) == 248
assert max_cycle(999999, 1) == 525
assert max_cycle(20, 20) == 8
assert max_cycle(9999, 9999) == 92
assert max_cycle(1, 9999) == 262
assert max_cycle(340, 3000) == 217
assert max_cycle(3000, 340) == 217
assert max_cycle(500, 101) == 144
assert max_cycle(1, 1) == 1
assert max_cycle(9999, 9998) == 92
t2 = time()
print "Tiempo de ejecucion %.3f s" % (t2 - t1)
#Tiempo de ejecucion 2.062 s
Saludos.