#
# Even Fibonacci numbers
# Problem 2
# 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.
#
class Problem_0002:
  
  def run(self):    
    result = 0
    currentNumber = 1
    nextNumber = 2
    sumOfEvenTerms = 0;
    
    #print "seq: {0}".format(currentNumber)
    
    while nextNumber < 4000000: # don't use range...  it requires a ton of allocation for 4,000,000 iterations
      #print "seq: {0}".format(nextNumber)
      #Check for even value term on the sequence to add
      if nextNumber % 2 == 0:
        sumOfEvenTerms += nextNumber
      
      #Standard temp value swap
      result = (currentNumber + nextNumber)
      currentNumber = nextNumber
      nextNumber = result
      
    print "Problem 2 Answer: {0}".format(sumOfEvenTerms);
    