3 ms·
That doesn't handle all the cases: what about fizz buzz bazz? Added: here's my version, which maybe could be cleaned up further. The spaces and exclamation poi
by throwaway81523 1y ago
That doesn't handle all the cases: what about fizz buzz bazz?
Added: here's my version, which maybe could be cleaned up further. The spaces and exclamation point make the problem trickier.
{-# LANGUAGE MonadComprehensions #-}
import Data.Maybe (catMaybes)
import Data.List (intercalate)
fizz :: Int -> String
fizz n = case zub of
[] -> show n
otherwise -> intercalate " " zub ++ "!"
where
f :: Int -> String -> Maybe String
f d msg = [msg | n`rem`d == 0]
zub = catMaybes . map (uncurry f)
$ [(3,"Fizz"), (5,"Buzz"), (7, "Bazz")]
main = mapM_ putStrLn [fizz n | n <- [1..110]]
- throwaway81523 1y agoimport Data.List (intercalate) fizzle :: Int -> String fizzle n = let ws = [(3,"Fizz"), (5,"Buzz"), (7,"Bazz")] a = [s | (d,s) <- ws, n`rem`d == 0] in case a of [] -> show n otherwise -> intercalate " " a ++ "!" main = mapM_ (putStrLn . fizzle) [1..110]