project-euler-100

[RADIOACTIVE] solutions to the first 100 challenges of project euler
git clone git://git.figbert.com/project-euler-100.git
Log | Files | Refs | README

commit 38b6f3783b2e663bb2f993577366a55d13ae2ed6
parent da714d2fc363c4ee8acfecbf94687632b5f089ff
Author: therealFIGBERT <figbertwelner@gmail.com>
Date:   Mon, 20 Jan 2020 15:22:03 -0800

Add solution to problem #2

Diffstat:
Aproblem002.py | 25+++++++++++++++++++++++++
1 file changed, 25 insertions(+), 0 deletions(-)

diff --git a/problem002.py b/problem002.py @@ -0,0 +1,25 @@ +# problemName = "Even Fibonacci numbers" +# problemNum = 2 +# solutionBy = "FIGBERT" +# language = "Python" +# dateCompleted = "20/01/2020" + +def fib(limit): + lst = [1,2] + while lst[-1] <= limit: + lst.append(lst[-2] + lst[-1]) + return lst + +def sumOfEvensInList(srcList): + lst = [] + for i in srcList: + if i % 2 == 0: + lst.append(i) + return sum(lst) + +fibUntil4Mil = fib(4000000) +answer = sumOfEvensInList(fibUntil4Mil) +print(( + "By considering the terms in the Fibonacci sequence whose values do not " + "exceed four million, the sum of the even-valued terms is {}".format(answer) +))