Haskell 001 with guards

This commit is contained in:
Correl Roush 2011-10-10 23:12:17 -04:00
parent 32f83b946f
commit 25798c7cc2

View file

@ -7,13 +7,10 @@
import Text.Printf import Text.Printf
multiples :: (Integral a) => a -> a multiples :: (Integral a) => a -> a
multiples max = multiples max
if max < 3 then | max < 3 = 0
0 | (max `mod` 5 == 0) || (max `mod` 3 == 0) = max + multiples (max - 1)
else | otherwise = multiples (max - 1)
if (max `mod` 5 == 0 || max `mod` 3 == 0) then
max + multiples (max - 1)
else multiples (max - 1)
main = do main = do
printf "Sum of multiples below 10: %d\n" (multiples 9 :: Int) printf "Sum of multiples below 10: %d\n" (multiples 9 :: Int)