Haskell Quiz/FizzBuzz/Solution Mikbe

From HaskellWiki
< Haskell Quiz‎ | FizzBuzz
Revision as of 08:27, 23 August 2011 by Mikbe (talk | contribs) (New page: I just started learning Haskell literally this week so I went with simple and straight forward. Can't wait till I learn a little so I can make this a one liner. <haskell> module Main wher...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

I just started learning Haskell literally this week so I went with simple and straight forward. Can't wait till I learn a little so I can make this a one liner.

module Main where
  
  main :: IO ()
  main = do 
    mapM_ (putStrLn . show) [fizzBuzz x | x <- [1..100]]

  fizz::Int->String
  fizz x = if x `mod` 3 == 0 then "Fizz" else ""

  buzz::Int->String
  buzz x = if x `mod` 5 == 0 then "Buzz" else ""

  fizzBuzz::Int->String
  fizzBuzz x = if fizz(x) ++ buzz(x) == "" 
    then show x 
    else fizz(x) ++ buzz(x)