Created
November 25, 2019 19:35
-
-
Save floh1695/91aa3e5b1199dd63a5e0c6647f05cba0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MultiplesOf3And5 where | |
solution :: Integer -> Integer | |
solution number = solutionInner (number - 1) 0 | |
solutionInner :: Integer -> Integer -> Integer | |
solutionInner number total = | |
if number <= 0 | |
then total | |
else solutionInner number' total' | |
where | |
number' = number - 1 | |
total' = | |
if number `divisibleBy` 3 || number `divisibleBy` 5 | |
then total + number | |
else total | |
divisibleBy :: Integer -> Integer -> Bool | |
divisibleBy n d = mod' == 0 | |
where | |
mod' = n `mod` d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment