mirror of
https://github.com/correl/euler.git
synced 2024-11-24 03:00:08 +00:00
Haskell 001 with guards
This commit is contained in:
parent
32f83b946f
commit
25798c7cc2
1 changed files with 4 additions and 7 deletions
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue