Skip to content

Instantly share code, notes, and snippets.

@tmiz
Created October 18, 2011 07:28
Show Gist options
  • Save tmiz/1294813 to your computer and use it in GitHub Desktop.
Save tmiz/1294813 to your computer and use it in GitHub Desktop.
fib using generator
def fib_gen_():
temp1,temp2 = 0,1
while 1:
yield temp1 + temp2
temp2,temp1 = temp1,temp2+temp1
def alt_fib(n):
if n==0:return 0
elif n==1:return 1
a = fib_gen_()
count = 0
while True:
count += 1
if n == count:
return a.next()
a.next()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment