|
|
@@ -0,0 +1,21 @@
|
|
|
+{-
|
|
|
+The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
|
|
|
+Find the sum of all the primes below two million.
|
|
|
+-}
|
|
|
+
|
|
|
+is_prime :: Int -> Bool
|
|
|
+is_prime x = go' x 2
|
|
|
+ where
|
|
|
+ go' :: Int -> Int -> Bool
|
|
|
+ go' 1 y = True
|
|
|
+ go' 2 y = True
|
|
|
+ go' x y
|
|
|
+ | x == y = True
|
|
|
+ | y == 2 = if (mod x y) == 0 then False else go' x 3
|
|
|
+ | otherwise = if (mod x y) == 0 then False else go' x (y+2)
|
|
|
+
|
|
|
+solution :: Int
|
|
|
+solution = sum (filter is_prime [2..2000000])
|
|
|
+
|
|
|
+main :: IO ()
|
|
|
+main = putStrLn ("Solution: " ++ show solution)
|