diff --git a/problems/002_problem.py b/problems/002_problem.py new file mode 100644 index 0000000..882de22 --- /dev/null +++ b/problems/002_problem.py @@ -0,0 +1,39 @@ + +# 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. +# + +import decorators + +@decorators.function_timer +def main(): + + count = 0 + limit = 4000000 + n1 = 1 + n2 = 1 + sumval = 0 + + while count <= limit: + + n3 = n1 + n2 + + if n3%2 == 0: + sumval += n3 + + n1 = n2 + n2 = n3 + count = n3 + + print("The sum is {}".format(sumval)) + +main() \ No newline at end of file