Fizzbuzz

From HaskellWiki
Revision as of 19:20, 1 March 2010 by AlexMcNeil (talk | contribs) (Started page, simple solution)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

I was reading this so I came up with a quick solution in Haskell.

fizz :: Int -> String
fizz n | n `mod` 15 == 0  = "FizzBuzz"
       | n `mod` 3  == 0  = "Fizz"
       | n `mod` 5  == 0  = "Buzz"
       | otherwise        = show n

main :: IO()
main = mapM_ putStrLn $ map fizz [1..100]

There's also a page Haskell Quiz/FizzBuzz with another solution.