Mi intento:
Código Python:
Ver originalcache = {}
def max_cycle(a, b):
def num(n):
ni = n
cnt = 1
if n in cache:
return cache[n]
else:
while not n == 1:
cnt += 1
if n%2 != 0:
n = (3*n)+1
else:
n = n/2
cache[ni] = cnt
return cache[ni]
def sec(a, b):
maxim = 0
if a > b: a,b = b,a
for i in xrange(a,b+1):
tr = num(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(1, 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 23.939 s
Hice lo que pude...
Cachear los resultados de cada numero no parece que sirva de mucho...
Saludos y gracias.