Skip to content

Instantly share code, notes, and snippets.

@wyager
Created June 27, 2019 06:51
Show Gist options
  • Save wyager/5ac6adab8f9659aa860c00bbef444291 to your computer and use it in GitHub Desktop.
Save wyager/5ac6adab8f9659aa860c00bbef444291 to your computer and use it in GitHub Desktop.
{-# 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