one-file-projects/fib.py

21 lines
250 B
Python
Raw Normal View History

2014-11-04 13:06:32 +01:00
from functools import lru_cache
@lru_cache(maxsize=1000)
def fibc(n):
if n < 2:
return 1
else:
return fibc(n-1)+fibc(n-2)
def fibs(n):
i = 1
a = 1
b = 1
while i < n:
(a,b) = (b,a+b)
i+=1
return b
print(fibc(1000))
print(fibs(1000))