Created
January 15, 2012 03:21
-
-
Save FGtatsuro/1614128 to your computer and use it in GitHub Desktop.
program 2 in 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
def fibo(): | |
a, b = 1, 2 | |
while True: | |
yield a | |
a, b = b, a + b | |
ans = [] | |
limit = 4000 * (10 ** 3) | |
f = fibo() | |
while True: | |
even = next(f) | |
print even | |
if even > limit: | |
break; | |
if even % 2 == 0: | |
ans.append(even) | |
print ans | |
print reduce(lambda x, y: x + y, ans) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment