|
|
@@ -0,0 +1,25 @@
|
|
|
+
|
|
|
+{-
|
|
|
+If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
|
|
|
+
|
|
|
+Find the sum of all the multiples of 3 or 5 below 1000.
|
|
|
+-}
|
|
|
+
|
|
|
+solution_is_div :: Int -> Int
|
|
|
+solution_is_div x = case (mod x 3) of
|
|
|
+ 0 -> x
|
|
|
+ _ -> case (mod x 5) of
|
|
|
+ 0 -> x
|
|
|
+ _ -> 0
|
|
|
+
|
|
|
+solution_inner :: Int -> Int
|
|
|
+solution_inner x = go' x 0 where
|
|
|
+ go' 1000 y = y
|
|
|
+ go' x y = go' (x+1) ((solution_is_div x) + y)
|
|
|
+
|
|
|
+solution :: Int
|
|
|
+solution =
|
|
|
+ solution_inner 0
|
|
|
+
|
|
|
+main :: IO ()
|
|
|
+main = putStrLn ("Solution: " ++ show solution)
|