September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,10 +1,7 @@
|
|||
def fib():
|
||||
"""Yield fib[n+1] + fib[n]"""
|
||||
yield 1 # have to start somewhere
|
||||
lhs, rhs = fib(), fib()
|
||||
yield next(lhs) # move lhs one iteration ahead
|
||||
while True:
|
||||
yield next(lhs)+next(rhs)
|
||||
def fib(n, c={0:1, 1:1}):
|
||||
if n not in c:
|
||||
x = n // 2
|
||||
c[n] = fib(x-1) * fib(n-x-1) + fib(x) * fib(n - x)
|
||||
return c[n]
|
||||
|
||||
f=fib()
|
||||
print [next(f) for _ in range(9)]
|
||||
fib(10000000) # calculating it takes a few seconds, printing it takes eons
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue