Haskell 005

This commit is contained in:
Correl Roush 2011-10-11 20:23:39 -04:00
parent ab80499b45
commit 9a94e60e14

20
haskell/e005.hs Normal file
View file

@ -0,0 +1,20 @@
{- What is the smallest number divisible by each of the numbers 1 to 20?
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 number that is evenly divisible by all of the numbers from 1 to 20?
-}
import Text.Printf
divisible n =
divisible_ n n 1
divisible_ _ 1 x = x
divisible_ n c x
| x `rem` c == 0 = divisible_ n (c - 1) x
| otherwise = divisible_ n n (x + 1)
main = do
printf "Foo\n"
printf "Smallest number divisible by 1-10: %d\n" (divisible 10 :: Integer)
printf "Smallest number divisible by 1-20: %d\n" (divisible 20 :: Integer)