From 78fbf8dbcf39aa51cf682a8795d0d0c3be6034c6 Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 16 Aug 2019 21:58:12 +0200 Subject: haskell problem 13 -> 18, 20 --- haskell/007-10001st_prime.hs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'haskell/007-10001st_prime.hs') 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] -- cgit