memofib.py 284 B

12345678910111213141516
  1. #!/usr/bin/env python
  2. fib_memo = {0:0, 1:1}
  3. def fib(x):
  4. if not x in fib_memo:
  5. fib_memo[x] = fib(x-1) + fib(x-2)
  6. return fib_memo[x]
  7. def main():
  8. for x in range(0,35):
  9. print fib(x)
  10. if __name__ == '__main__':
  11. import cProfile
  12. cProfile.run('main()')