euler

git clone git://git.codymlewis.com/euler.git
Log | Files | Refs

commit f3fee581272acaf610fcd5589ea5e3e25ab8c1d3
parent cb81a9cc0edcd47c34d1af1702dbb7b9fd0f4b38
Author: Cody Lewis <luxdotsugi@gmail.com>
Date:   Sun, 18 Nov 2018 18:42:49 +1100

Fixed the finding algorithm, also made the loop neater

Diffstat:
MSeven.py | 11+++++------
1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/Seven.py b/Seven.py @@ -10,17 +10,16 @@ What is the 10 001st prime number? def prime(n): # could cheat with SymPy, but that is not fun. i = 2 - prime_count = 0 - while True: + prime_count = 1 + while prime_count < n: + i += 1 if is_prime(i): prime_count += 1 - if prime_count == n: - return i - i += 1 + return i def is_prime(n): - for i in range(2, int(math.ceil(math.sqrt(n)))): + for i in range(2, int(math.ceil(math.sqrt(n))) + 1): if (n % i) == 0: return False return True