> f=lambda n:(b:=2<<n)*n*b//(b*b-b-1)%b
> [f(n) for n in range(10)]
> [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
Or in Haskell, without the cute generating function tricks:
take 10 $ let f a b = a : f b (a+b) in f 0 1
> [f(n) for n in range(10)]
> [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
Or in Haskell, without the cute generating function tricks:
take 10 $ let f a b = a : f b (a+b) in f 0 1
f = 0:1:zipWith (+) f (tail f) from itertools import pairwise, chain
def f(): yield from chain([0,1], map(sum, pairwise(f())))
There's a Joel Grus post discussing it: https://joelgrus.com/2015/07/07/haskell-style-fibonacci-in-p...The introduction of pairwise in 3.10 made possible to write it more compactly, when compared to the version discussed by Joel.