June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,10 +1,8 @@
|
|||
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)
|
||||
|
||||
f=fib()
|
||||
print [next(f) for _ in range(9)]
|
||||
F = {0: 0, 1: 1, 2: 1}
|
||||
def fib(n):
|
||||
if n in F:
|
||||
return F[n]
|
||||
f1 = fib(n // 2 + 1)
|
||||
f2 = fib((n - 1) // 2)
|
||||
F[n] = (f1 * f1 + f2 * f2 if n & 1 else f1 * f1 - f2 * f2)
|
||||
return F[n]
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
from itertools import islice
|
||||
|
||||
def fib():
|
||||
yield 0
|
||||
yield 1
|
||||
a, b = fib(), fib()
|
||||
next(b)
|
||||
"""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(a)+next(b)
|
||||
yield next(lhs)+next(rhs)
|
||||
|
||||
print(tuple(islice(fib(), 10)))
|
||||
f=fib()
|
||||
print [next(f) for _ in range(9)]
|
||||
|
|
|
|||
11
Task/Fibonacci-sequence/Python/fibonacci-sequence-13.py
Normal file
11
Task/Fibonacci-sequence/Python/fibonacci-sequence-13.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
from itertools import islice
|
||||
|
||||
def fib():
|
||||
yield 0
|
||||
yield 1
|
||||
a, b = fib(), fib()
|
||||
next(b)
|
||||
while True:
|
||||
yield next(a)+next(b)
|
||||
|
||||
print(tuple(islice(fib(), 10)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue