>(the solution, of course, is to avoid storing all those numbers in the
>first place)

I tried this:

fib = {0:0,1:1}
sum = 0

for j in xrange (2,1000000):
    i = fib[j-1] + fib[j-2]
    if i % 2 == 0:
        sum += i
    fib = {j-1:fib[j-1], j:i}

print sum

I guess it should come up with the right answer (i compared sum to the
total value for small values in the range and they were the same)

Just storing the value of the sum doesn't use that much memory and
prints the sum for (2, 1 million) but it takes a long time to compute.
I know there has to be a way better solution.
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to