Created
December 10, 2011 11:26
-
-
Save carnotweat/1454954 to your computer and use it in GitHub Desktop.
euler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fib1 | |
========= | |
`def fib(a=0, b=1): | |
while True: | |
yield a | |
a, b = b, a + b | |
sum_ = 0 | |
for f in fib(): | |
if f > 4000000: | |
break | |
if f % 2 == 0: | |
sum_ += f | |
print sum_` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fib(n): | |
if n == 0: | |
return 0 | |
elif n == 1: | |
return 1 | |
else: | |
return fib(n-1) + fib(n-2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment