Created
June 27, 2019 06:51
-
-
Save wyager/5ac6adab8f9659aa860c00bbef444291 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
{-# LANGUAGE BangPatterns #-} | |
import System.Environment (getArgs) | |
add :: Int -> Int -> Int | |
add start stop = go (start `mod` 3) (start `mod` 5) 0 start | |
where | |
go !a !b !acc !i | |
| i == stop = acc | |
| otherwise = go a' b' acc' (i+1) | |
where | |
a' = if a == 2 then 0 else a + 1 | |
b' = if b == 4 then 0 else b + 1 | |
acc' = if a == 0 || b == 0 then acc + i else acc | |
main :: IO () | |
main = do | |
[start, stop] <- map read <$> getArgs | |
print (add start stop) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment