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 9de60a9e8e03e20836b743281af0a25e18054e7a
parent 6e3f3adbfefdbaa4f5b180f59450d220c91856d4
Author: therealFIGBERT <figbertwelner@gmail.com>
Date:   Wed, 29 Jan 2020 12:47:05 -0800

Add solution to problem 10

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

diff --git a/problem010.py b/problem010.py @@ -0,0 +1,19 @@ +# problemName = "Summation of primes" +# problemNum = 10 +# solutionBy = "FIGBERT" +# language = "Python" +# dateCompleted = "28/01/2020" + +def sieveOfEratosthenes(limit): + prime = [True for _ in range(limit+1)] + p = 2 + while (p * p <= limit): + if (prime[p] == True): + for i in range(p * 2, limit + 1, p): + prime[i] = False + p += 1 + prime[0:2] = [False, False] + return [p for p in range(limit + 1) if prime[p]] + +primes = sieveOfEratosthenes(2000000) +print(f"The sum of all the primes below two million is {sum(primes)}")