Language Shootout

Fredrik Lundh fredrik at pythonware.com
Mon Jul 9 18:11:02 EDT 2001


Paul Winkler wrote:
> Doing it iteratively is much, much faster.

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>





More information about the Python-list mailing list