text: #! /usr/bin/env python
  
  #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.
  
  import math
  
  def FibSequence(maximum):
    a = 1; yield a;
    b = 1; yield b;
    while b < maximum:
      a, b = b, a + b
      yield b
  
  def BruteForceSolution():
    result = sum(x for x in FibSequence(maximum=4000000) if x % 2 == 0)
    print("Brute force result: %d" % result)
  
  BruteForceSolution()
  
  # There is an elegant math solution using the formula: fib(n) = (phi^n - psi^n) / sqrt(5)
  # Every 3rd fib number is even, to evenFib(n) = (phi^3n - psi^3n) / sqrt(5)
  # sumEvenFibsi(n) = 1 / sqrt(5) * (SumGeometricSequence(initial=phi, ratio=phi^3, num=n) - SumGeometricSequence(psi, psi^3, n))
  # I just don't know how many even fibs are there between 1 and 4000000 ??
  