Language Shootout

Bengt Richter bokr at accessone.com
Mon Jul 9 21:51:52 EDT 2001


On Mon, 09 Jul 2001 22:11:02 GMT, "Fredrik Lundh"
<fredrik at pythonware.com> wrote:

>Paul Winkler wrote:
>> Doing it iteratively is much, much faster.
Not necessarily. See my other post ;-)

>
>does your fastest iterative solution beat this one?
>
>import sys
>
>def fib(n):
>    if n < 2:
>        return 1
>    return fib(n-2) + fib(n-1)
>
>def fib(n, fib=fib, memo={}):
>    v = memo.get(n)
>    if v is None:
>        v = memo[n] = fib(n)
>    return v
>
>def main():
>    N = int(sys.argv[1])
>    print fib(N)
>
></F>
>
>
My algorithm will beat this easily when
n gets big. But I like the memo thing.
That could improve mine too.





More information about the Python-list mailing list