# Project Euler: Even Fibonacci Numbers
# Status: COMPLETE

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

def main():

    n = 1

    listOf = []

    recursive(n, n, listOf) # Recurses to find the even-valued terms in the Fibobacci sequence
    sumOf(listOf) # Computes the sum of the even-valued terms

def recursive(currentNumber, previousNumber, listOf):
    # Recurses to find the even-valued terms in the Fibobacci sequence

    if (currentNumber >= 4000000):
        return listOf # Base case
    else:
        newCurrentNumber = currentNumber + previousNumber
        previousNumber = currentNumber

        if (newCurrentNumber % 2 == 0) and (newCurrentNumber < 4000000):
            listOf.append(newCurrentNumber)
            
        recursive(newCurrentNumber, previousNumber, listOf) # Recursive case

def sumOf(listOf):
    # Computes the sum of the even-valued terms

    evenSum = 0

    for evenNumber in listOf:
        evenSum += evenNumber

    print(evenSum)

main()
