Skip to content

Instantly share code, notes, and snippets.

@gr33ndata
Created January 31, 2014 07:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gr33ndata/8727727 to your computer and use it in GitHub Desktop.
Save gr33ndata/8727727 to your computer and use it in GitHub Desktop.
Even Fibonacci numbers
# Solving this problem:
# http://projecteuler.net/problem=2
# Sum: 4,613,732
def fab(a,b, maxlimit):
while b < maxlimit:
yield b
a, b = b, a+b
if __name__ == "__main__":
sum = 0
for b in fab(1,1,4000000):
if not b % 2:
sum += b
print b, sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment