blob: 87486bda1ab7ca3c06a1e0e1a397c45ac5f1205c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
nthPrime :: Integer -> Integer
nthPrime targetCount = nextPrimeImpl 2 1 []
where
nextPrimeImpl i primeCount primeList =
if isPrime then
if primeCount == targetCount then
i
else
nextPrimeImpl (i + 1) (primeCount + 1) (primeList ++ [i])
else
nextPrimeImpl (i+1) primeCount primeList
where
isPrime =
isPrimeImpl primeList
where
isPrimeImpl [] = True
isPrimeImpl (x:xs) = i `mod` x /= 0 && isPrimeImpl xs
main = do
putStrLn $ show $ nthPrime 10001
|