Skip to content

Instantly share code, notes, and snippets.

@MgaMPKAy
Created May 5, 2014 18:12
Show Gist options
  • Save MgaMPKAy/9dfb53488077b0fd63a4 to your computer and use it in GitHub Desktop.
Save MgaMPKAy/9dfb53488077b0fd63a4 to your computer and use it in GitHub Desktop.
FizzBuzzWhizz
import Data.Monoid
import Data.Maybe
fizzBuzzWhizz (x, y, z) a =
fromJust $ getFirst $ mconcat $ map First
[ x `contains` a
, fizz a x <> buzz a y <> whizz a z
, Just $ show a
]
where
contains x a = toMaybe (head (show x) `elem` show a) "Fizz"
[fizz, buzz, whizz] = map mkRule2 ["Fizz", "Buzz", "Whizz"]
mkRule2 str x y = toMaybe (x `rem` y == 0) str
toMaybe True a = Just a
toMaybe _ _ = Nothing
main = do
[x, y, z] <- fmap (map read . splitOn ',') getLine
mapM_ (putStrLn . fizzBuzzWhizz (x,y,z)) [1..100]
splitOn sep ls =
case break (== sep) ls of
(h, "") -> [h]
(h, t) -> h : splitOn sep (tail t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment