[Tutor] Tutor Digest, Vol 53, Issue 99
alan.gauld at btinternet.com
Tue Jul 29 09:44:40 CEST 2008
"kinuthiA muchanE" <muchanek at gmail.com> wrote
> I have realised that when you need to work with large numbers, lists
> 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
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
More information about the Tutor