"Alan Gauld" <[EMAIL PROTECTED]> wrote > were infinite using floats! So you need to calculate the > total as you go without saving the values >
I got curious so wrote the following function: >>> def fibtot(N): ... f0,f1,tot = 0,1,1 ... for n in range(N): ... f = f0 + f1 ... f0,f1 = f1,f ... if n % 2 == 0: tot += f ... return tot and here are the results... >>> len(str(fibtot(10000))) 2090 >>> len(str(fibtot(100000))) 20899 >>> len(str(fibtot(200000))) 41798 >>> len(str(fibtot(400000))) 83595 >>> len(str(fibtot(500000))) 104494 >>> len(str(fibtot(600000))) 125393 >>> len(str(fibtot(800000))) 167190 >>> len(str(fibtot(1000000))) 208988 >>> So the final total contains nearly 209 thousand digits! Thats a very, very big number... and it took 5 minutes to compute on my PC (Dual core 2.8GHz with 2G RAM) Now I really must go to bed :-) -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor