Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
31
Task/Fibonacci-sequence/Python/fibonacci-sequence-14.py
Normal file
31
Task/Fibonacci-sequence/Python/fibonacci-sequence-14.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
'''Fibonacci accumulation'''
|
||||
|
||||
from itertools import accumulate, chain
|
||||
from operator import add
|
||||
|
||||
|
||||
# fibs :: Integer :: [Integer]
|
||||
def fibs(n):
|
||||
'''An accumulation of the first n integers in
|
||||
the Fibonacci series. The accumulator is a
|
||||
pair of the two preceding numbers.
|
||||
'''
|
||||
def go(ab, _):
|
||||
return ab[1], add(*ab)
|
||||
|
||||
return [xy[1] for xy in accumulate(
|
||||
chain(
|
||||
[(0, 1)],
|
||||
range(1, n)
|
||||
),
|
||||
go
|
||||
)]
|
||||
|
||||
|
||||
# MAIN ---
|
||||
if __name__ == '__main__':
|
||||
print(
|
||||
'First twenty: ' + repr(
|
||||
fibs(20)
|
||||
)
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue