On Tue, 2008-07-29 at 12:00 +0200, [EMAIL PROTECTED] wrote: > Message: 2 > Date: Tue, 29 Jul 2008 08:44:40 +0100 > From: "Alan Gauld" <[EMAIL PROTECTED]> > Subject: Re: [Tutor] Tutor Digest, Vol 53, Issue 99 > To: tutor@python.org > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; format=flowed; charset="iso-8859-1"; > reply-type=original > > "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! I think the question is to calculate the sum of all even numbers in the Fibonacci series which do not exceed a million, not the millionth term. Number 25 on Project Euler which asks for first term in the Fibonacci series to contain 1000 digits, is the term-wise question ;) > > > 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