Skip to content

Instantly share code, notes, and snippets.

@yyl
Created July 16, 2012 03:50
Show Gist options
  • Save yyl/3120376 to your computer and use it in GitHub Desktop.
Save yyl/3120376 to your computer and use it in GitHub Desktop.
fibonacci generator
def fibo_gen():
a = 1
b = 1
while 1:
yield a
a, b = b, a+b
a = fibo_gen()
f = a.next()
count = 1
while 1:
if len(str(f)) == 1000:
print count
break
f = a.next()
count += 1
def fibo(i):
if i == 1 or i == 2:
return 1
return fibo(i-1) + fibo(i-2)
count = 10
while True:
f = fibo(count)
if len(str(f)) == 1000:
print "got", f
break
count += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment