18 lines
310 B
Python
18 lines
310 B
Python
|
|
def fibonacci():
|
|
a, b = 1, 1
|
|
while True:
|
|
yield a
|
|
a, b = b, a + b
|
|
|
|
def target_sum(limit, match):
|
|
total = 0
|
|
for x in fibonacci():
|
|
if x >= limit:
|
|
break
|
|
if match(x):
|
|
total += x
|
|
return total
|
|
|
|
print(target_sum(4000000, lambda x: not (x & 1)))
|