I'm currently working through the Project Euler Problems using HackerRank to evaluate the code and I'm stuck on the 7th Problem.
"""
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
What is the 10 001st prime number?
"""
import pytest
def find_primes(limit):
nums = [True] * (limit+1)
nums[0] = nums[1] = False
for (i, is_prime) in enumerate(nums):
if is_prime:
yield i
for n in range(i*i, limit+1, i):
nums[n] = False
def find_n_prime(n):
for i in range(n, (n*n)+1, n):
primes = list(find_primes(i))
if len(primes) >= n:
return primes[n-1]
def test_find_n_primes():
assert find_n_prime(2) == 3
assert find_n_prime(3) == 5
assert find_n_prime(10) == 29
assert find_n_prime(15) == 47
assert find_n_prime(81) == 419
assert find_n_prime(941) == 7417
assert find_n_prime(1000) == 7919
assert find_n_prime(10001) == 104743
The code only completes the first test case on hackerRank and fails for #2 test case and times out for the rest.
How can I improve the Code ?