aboutsummaryrefslogtreecommitdiff
path: root/haskell/010-summation_of_primes.hs
diff options
context:
space:
mode:
Diffstat (limited to 'haskell/010-summation_of_primes.hs')
-rw-r--r--haskell/010-summation_of_primes.hs16
1 files changed, 16 insertions, 0 deletions
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]