- #1
~Death~
- 45
- 0
im trying to do the Euler problem #14 - to determine which starting value under one million produces the longest chain
and here's my code in Python
However, I left it on all night and it still did not finish
but it works for lower numbers like for in in range(1,1000) only takes a few seconds
anyone know what my problem is?
Thanks
and here's my code in Python
Code:
Count=[]
Count2=[]
List=[]
def seq(n):
if n%2==0:
return n/2
else:
return 3*n+1
m=1
for i in range(1,1000000):
j=i
List.append(j)
while seq(j)>1:
List.append(seq(j))
j=seq(j)
List.append(1)
Count.append(len(List))
List=[] #Reset List
if max(Count)>m:
m=max(Count)
Count2.append((m,i))
print Count2[len(Count2)-1]
raw_input("...")
but it works for lower numbers like for in in range(1,1000) only takes a few seconds
anyone know what my problem is?
Thanks
Last edited: