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 8d23e4218ac93379ff95506c0a31eccd90b33bcc
parent 41457cf3cbcb98262f3b9bed42d96ee7348418b7
Author: therealFIGBERT <figbertwelner@gmail.com>
Date:   Fri, 24 Jan 2020 19:40:26 -0800

Add solution to problem 7

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

diff --git a/problem007.py b/problem007.py @@ -0,0 +1,29 @@ +# problemName = "10001st prime" +# problemNum = 7 +# solutionBy = "FIGBERT" +# language = "Python" +# dateCompleted = "24/01/2020" +# https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes +import math + +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]= False + prime[1]= False + return [p for p in range(limit + 1) if prime[p]] + +def search(): + searchRange = 100 + returnValue = sieveOfEratosthenes(searchRange) + while len(returnValue) < 10001: + searchRange += 100 + returnValue = sieveOfEratosthenes(searchRange) + print(returnValue[10000]) + +search() +\ No newline at end of file