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

# 4 million is the max
# only evens

max_number = 4000000

placeholder_fib = 1
fib_number = 1
last_fib = 1
even_fib_sum = 0
fib_sequence = [] # check to make sure fib numbers are correct

while fib_number < max_number:
    if fib_number % 2 == 0:
        # add even fib numbers to even_fib 
        fib_sequence.append(fib_number)
        placeholder_fib = fib_number
        even_fib_sum += fib_number
        fib_number += last_fib
        last_fib = placeholder_fib      
    else:
        # only increase fib_number 
        fib_sequence.append(fib_number)
        placeholder_fib = fib_number
        fib_number += last_fib
        last_fib = placeholder_fib
        
print(even_fib_sum)
print(fib_sequence)