Haskell Quiz/FizzBuzz/Solution Ninju: Difference between revisions
< Haskell Quiz | FizzBuzz
No edit summary |
m (Reverted edits by Tomjaguarpaw (talk) to last revision by Syzygies) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
[[Category:Haskell Quiz solutions|FizzBuzz]] | [[Category:Haskell Quiz solutions|FizzBuzz]] | ||
I think this is probably what I'd do in the interview situation - i.e. the first and most obvious thing that comes to mind. | I think this is probably what I'd do in the interview situation - i.e. the first and most obvious thing that comes to mind. | ||
<haskell> | <haskell> | ||
Line 17: | Line 17: | ||
| n `mod` 3 == 0 = "Buzz" | | n `mod` 3 == 0 = "Buzz" | ||
| otherwise = show n | | otherwise = show n | ||
</haskell> | </haskell> |
Latest revision as of 15:19, 6 February 2021
I think this is probably what I'd do in the interview situation - i.e. the first and most obvious thing that comes to mind.
module Main where
main :: IO ()
main = printAll $ map fizzBuzz [1..100]
where
printAll [] = return ()
printAll (x:xs) = putStrLn x >> printAll xs
fizzBuzz :: Integer -> String
fizzBuzz n | n `mod` 15 == 0 = "FizzBuzz"
| n `mod` 5 == 0 = "Fizz"
| n `mod` 3 == 0 = "Buzz"
| otherwise = show n