Skip to content

Instantly share code, notes, and snippets.

@floh1695
Created November 25, 2019 19:35
Show Gist options
  • Save floh1695/91aa3e5b1199dd63a5e0c6647f05cba0 to your computer and use it in GitHub Desktop.
Save floh1695/91aa3e5b1199dd63a5e0c6647f05cba0 to your computer and use it in GitHub Desktop.
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