Problem 2 - Even Fibonacci Numbers

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, ...

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
The Idea

Using the formula
Fn=Fn1+Fn2 for n2 F_{n} = F_{n-1} + F_{n-2} \text{ for } n \geq 2
F0=1,F1=2 F_{0} = 1, F_{1} = 2

we simply calculate each fibonacci up to (and possibly including) 4 million. For each fibonacci number, we add it to the total if it is even.

The Code


The full utils module can be found on GitHub here

© Jack Moody 2020