I'm attempting some Project Euler problems in an attempt to learn Python, and while. While I can get the correct answer quite easily, my programs are quite slow. Project Euler, if doing it correctly, specifies that each program should run in <1 minute. Some of mine take 5-10 mins.
HereHere is one example: http://projecteuler.net/problem=14.
x=1;
terms=0;
maxTerms=0;
maxTermsNum=0;
for x in range(1,1000000):
i=x;
while (i!=1):
terms+=1;
if (i%2==0):
i/=2
else:
i=3*i+1
if (terms>maxTerms):
maxTerms=terms;
maxTermsNum=x;
print(x);
terms=0;
print("Biggest one: is %s." %maxTermsNum)
This is the program. It produces the correct answer, but it takes a long long time. How can I speed this up? Using Python, again, This is also in 32bit32-bit Windows.