Project Euler Problem #2:
Each new term in the Fibonacci sequence is generated by adding the previous two terms.
Find the sum of all the even-valued terms in the sequence which do not exceed four million.
Again the solution is provided in python.
Fibs = [1, 2]
def Fib(prev1, prev2, end):
if (prev1+prev2 > end):
return 0
else:
global Fibs
cur = prev1 + prev2
Fibs.append(cur)
Fib(prev2, cur, end)
Fib(1, 2, 4000000)
Lies = []
for F in Fibs:
if F%2 == 0:
Lies.append(F)
sum = 0
for l in Lies:
sum = sum + l
print sum