Skip to content

Instantly share code, notes, and snippets.

@shieldsd
Created March 13, 2012 08:43
Show Gist options
  • Save shieldsd/2027626 to your computer and use it in GitHub Desktop.
Save shieldsd/2027626 to your computer and use it in GitHub Desktop.
Project Euler #2
from itertools import takewhile
def fib():
a, b = 1, 1
while 1:
yield a
a, b = b, a + b
print sum(n for n in takewhile(lambda f: f < 4000000, fib()) if n % 2 == 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment