mirror of
https://github.com/correl/euler.git
synced 2024-11-27 11:09:54 +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
|
||||
|
||||
multiples :: (Integral a) => a -> a
|
||||
multiples max =
|
||||
if max < 3 then
|
||||
0
|
||||
else
|
||||
if (max `mod` 5 == 0 || max `mod` 3 == 0) then
|
||||
max + multiples (max - 1)
|
||||
else multiples (max - 1)
|
||||
multiples max
|
||||
| max < 3 = 0
|
||||
| (max `mod` 5 == 0) || (max `mod` 3 == 0) = max + multiples (max - 1)
|
||||
| otherwise = multiples (max - 1)
|
||||
|
||||
main = do
|
||||
printf "Sum of multiples below 10: %d\n" (multiples 9 :: Int)
|
||||
|
|
Loading…
Reference in a new issue