From bb515e51d67f37ba9c6dfbd2fd0930be873a5ada Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 12 Aug 2019 15:47:31 +0200 Subject: haskell problems 007 -> 010 --- haskell/010-summation_of_primes.hs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 haskell/010-summation_of_primes.hs (limited to 'haskell/010-summation_of_primes.hs') diff --git a/haskell/010-summation_of_primes.hs b/haskell/010-summation_of_primes.hs new file mode 100644 index 0000000..e8d8015 --- /dev/null +++ b/haskell/010-summation_of_primes.hs @@ -0,0 +1,16 @@ +-- Summation of primes + +-- Problem 10 +-- The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. + +-- Find the sum of all the primes below two million. + + +main = do + print (sum $ eratos_sieve [2..1999999]) + +eratos_sieve :: [Int] -> [Int] +eratos_sieve [] = [] +eratos_sieve (x:xs) + | x * x > last xs = x:xs + | otherwise = x:eratos_sieve [n | n <- xs, n `mod` x /= 0] -- cgit