Guest User

improved fibonacci sequence

a guest
May 12th, 2011
147
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. cached_results = []
  2.  
  3. def fib_rec(n):
  4.     for i in range(0, n):
  5.         if i < 2:
  6.             cached_results.append(i)
  7.         else:
  8.             cached_results.append(cached_results[0] + cached_results[1])
  9.             del cached_results[0]
  10.    
  11.     return cached_results[1]
  12.            
  13. if __name__ == "__main__":
  14.     print fib_rec(41)
RAW Paste Data