Problem:
Each new term in the Fibonacci sequence is generated by adding the previous two terms.
By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
Find the sum of all the even-valued terms in the sequence which do not exceed four million.
Solution:
I think this problem can only be solved programmatically, so here it goes in Ruby of course:
limit = 4000000 fib1, fib2, sum = 1, 1, 0 while fib2 < limit do fib1 += fib2 fib2 += fib1 sum += (fib1 % 2 == 0 ? fib1 : 0) sum += (fib2 % 2 == 0 ? fib2 : 0) end p sum
Answer: 4613732

MeasureIt