From b22bdff9ca08e0e8b217b4483d97d081b1c02ebf Mon Sep 17 00:00:00 2001 From: Shaun Setlock Date: Tue, 14 Apr 2020 21:25:14 -0400 Subject: [PATCH] Automatic commit performed through alias... --- problems/002_problem.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 problems/002_problem.py 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