Skip to content

Instantly share code, notes, and snippets.

@orblivion
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orblivion/057fc395e4d87af97fba to your computer and use it in GitHub Desktop.
Save orblivion/057fc395e4d87af97fba to your computer and use it in GitHub Desktop.
Recursive lazy fibonacci
from itertools import izip, islice
def fibg():
"Generate an infinite amount of fibonacci numbers"
yield 1
yield 1
offset = fibg()
offset.next()
for x, y in izip(offset, fibg()):
yield x + y
def fib(n):
"Return a list of the first n elements of the fibonacci sequence"
return list(islice(fibg(), 0, n))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment