# Project Euler # 2

Project Euler # 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-value terms.

My approach in Python:

Includes a recursive function to generate a finite set of fibonacci numbers, which are then summed within a generator expression.

LOC: 7 lines

Uses a recursive function to generate an infinite set of fibonacci numbers, which are filtered and summed within a list comprehension.

LOC: 3

Optimisation Discussion:
I find this Project Euler challenge really interesting. Some of the later challenges require you to find “optimal” or “near-optimal” solutions because the naive solution is just so slow. However, this isn’t really the case here. There are certainly more optimal solutions:

• sum the entire fibonacci sequence (below 4,000,000 limit) and halve it
• sum every third term in the fibonacci sequence
• certain mathematical fibonacci generators

However, only 33 terms exist beneath the 4,000,000 limit. With this in mind, there is little practical advantage to optimisation. And this, IMHO, is the most interesting thing in this challenge: the balance between elegance and practicality. In most situations I lean towards the former, there is beauty in finding more elegant solutions.