Jelajahi Sumber

[Haskell][5] Adding solution

Vinicius Teshima 5 bulan lalu
induk
melakukan
96398bc6d0
1 mengubah file dengan 18 tambahan dan 0 penghapusan
  1. 18 0
      haskell/src/0005.hs

+ 18 - 0
haskell/src/0005.hs

@@ -0,0 +1,18 @@
+{-
+2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
+What is the smallest positive number that is evenly divisible with no remainder by all of the numbers from 1 to 20?
+-}
+
+evenly_div :: Int -> Int -> Bool
+evenly_div x 0 = True
+evenly_div x 1 = True
+evenly_div x y = if (mod x y) == 0 then evenly_div x (y - 1) else False
+
+solution' :: Int -> Int
+solution' x = if (evenly_div x 20) then x else solution' (x + 1)
+
+solution :: Int
+solution = solution' 1
+
+main :: IO ()
+main = putStrLn ("Solution: " ++ show solution)