On Tue, 10 Feb 2009 02:05:35 -0800, Niklas Norrthon wrote: > According to the common definition of fibonacci numbers fib(0) = 0, fib > (1) = 1 and fib(n) = fib(n-1) + fib(n-2) for n > 1. So the number above > is fib(501).
So it is. Oops, off by one error! Or, if you prefer, it's the right algorithm for a Lucas sequence with first two values 1 and 1 instead of 0 and 1. :) >>>> timeit.Timer('fib(500)', 'from __main__ import fib').timeit(1) >> >> 0.00083398818969726562 > > And now for my version (which admitedly isn't really mine, and returns > slightly incorrect fib(n) for large values of n, due to the limited > floating point precision). The floating point version is nice, but it starts giving incorrect answers relatively early, from n=71. But if you don't need accurate results (a relative error of 3e-15 for n=71), it is very fast. -- Steven -- http://mail.python.org/mailman/listinfo/python-list