# -*- coding: utf-8 -*-
"""
Created on Mon Oct 12 10:05:22 2020

@author: Mr. Conrad
"""
'''
Let's try to solve this problem quicker than the last.
Than the last we won't have forever in an interview after all!
'''
print('''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.''')

#STEP 1: create a fibonacci generator

#The first two numbers in sequence
prev = 1
fib = 2

#placeholder
temp = 0
fib_sum = 0
print(str(prev) + ',', end='')
while fib < 4000000:
    if fib % 2 == 0:
        fib_sum += fib
    print(str(fib) + ',', end='')
    temp = fib
    fib += prev
    prev = temp
else:
    print(fib)
    
print("Solution: " + str(fib_sum))
