"kinuthiA muchanE" <[EMAIL PROTECTED]> wrote
I have realised that when you need to work with large numbers, lists
are
slow and tend to gobble up bytes.
The lists are not particularly slow (obviously if you want to
traverse them they take longer for more members) and they
don't take up much more memory that the sum of the sizes
of whats in them.
The problem here is that the data items themselves are huge.
Around 20K per item. Thus a million times 20K is 20G!
This is how I would approach the problem, without using
lists.
Yep, we all seem to be pretty much in agreement :-)
It produces the result instantly, even for large numbers like a
100, 000, 000.
Umm, not instantly on my PC... 1 million took 5 minutes,
I've no idea how long 100 million would take!
def fibonacci()
a = 0
b = 1
evenTotal = 0
while a < 100000000:
a,b = b,a+b
if a%2 == 0:
evenTotal += a
print evenTotal
Alan G
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor