def euler14(limit):
kNum = limit - 1
maxLen = 0
def kollats(number):
kolNums = [number]
while True:
n = kolNums[len(kolNums) - 1]
if n == 1:
break
if n % 2:
n = 3*n + 1
else:
n = int(n / 2)
kolNums.append(n)
return kolNums
for i in range(1, limit):
kol = kollats( kNum )
if len(kol) > maxLen:
maxLen = len(kol)
kNum -= 1
print(maxLen)
euler14(1000000)
def euler14(limit):
cache, kolNums = {1: 1}, []
for n in range(2, limit):
while n not in cache:
kolNums.append(n)
n = 3 * n + 1 if n % 2 else n // 2
res = cache[n]
while kolNums:
res += 1
cache[kolNums.pop()] = res
print(*max(cache.items(), key=lambda e: e[1]))