aboutsummaryrefslogtreecommitdiff
path: root/haskell/007-10001st_prime.hs
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-08-16 21:58:12 +0200
committerCharles <sircharlesaze@gmail.com>2019-08-16 21:58:12 +0200
commit78fbf8dbcf39aa51cf682a8795d0d0c3be6034c6 (patch)
tree33ebc93733d3406422e5cd0defed3869e9c68b92 /haskell/007-10001st_prime.hs
parentbb515e51d67f37ba9c6dfbd2fd0930be873a5ada (diff)
downloadproject_euler-78fbf8dbcf39aa51cf682a8795d0d0c3be6034c6.tar.gz
project_euler-78fbf8dbcf39aa51cf682a8795d0d0c3be6034c6.tar.bz2
project_euler-78fbf8dbcf39aa51cf682a8795d0d0c3be6034c6.zip
haskell problem 13 -> 18, 20
Diffstat (limited to 'haskell/007-10001st_prime.hs')
-rw-r--r--haskell/007-10001st_prime.hs4
1 files changed, 4 insertions, 0 deletions
diff --git a/haskell/007-10001st_prime.hs b/haskell/007-10001st_prime.hs
index c775f7d..47cb355 100644
--- a/haskell/007-10001st_prime.hs
+++ b/haskell/007-10001st_prime.hs
@@ -13,6 +13,7 @@ main = do
-- to the arbirary range
print (nth_prime 10000) -- better but meh since we're testing every divisor each time,
-- should keep a list of them
+ -- print (primes !! 10000) -- from the haskell website, stream of numbers (takes forever)
nth_prime :: Int -> Int
nth_prime n = nth_check n 0
@@ -39,3 +40,6 @@ is_prime x
| x `mod` d == 0 || x `mod` (d + 2) == 0 = False
| otherwise = trial_div (d + 6)
+primes :: [Int]
+primes = filterPrimes [2..]
+ where filterPrimes (p:xs) = p : filterPrimes [x | x <- xs, x `mod` p /= 0]