Difference between revisions of "Haskell Quiz/FizzBuzz/Solution Ninju"
< Haskell Quiz | FizzBuzz
Jump to navigation
Jump to search
(Moved my solution to its own page, following quiz convention.) |
Tomjaguarpaw (talk | contribs) (Remove old, not very useful page) |
||
Line 1: | Line 1: | ||
− | [[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. |
||
− | |||
− | <haskell> |
||
− | 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 |
||
− | </haskell> |