HaskellWiki

Haskell | Wiki community | Recent changes
Random page | Special pages

 

Not logged in
Log in | Help

Haskell Quiz/FizzBuzz/Solution Ninju

< Haskell Quiz | FizzBuzz

Categories: Haskell Quiz solutions


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

Retrieved from "http://haskell.org/haskellwiki/Haskell_Quiz/FizzBuzz/Solution_Ninju"

This page has been accessed 125 times. This page was last modified 22:16, 12 August 2008. Recent content is available under a simple permissive license.