Difference between revisions of "Fizzbuzz"
Jump to navigation
Jump to search
Tomjaguarpaw (talk | contribs) (Remove old pointless page) |
m (Reverted edits by Tomjaguarpaw (talk) to last revision by AlexMcNeil) |
||
Line 1: | Line 1: | ||
+ | I was reading [http://imranontech.com/2007/01/24/using-fizzbuzz-to-find-developers-who-grok-coding/ this] so I came up with a quick solution in Haskell. |
||
+ | |||
+ | <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] |
||
+ | </haskell> |
||
+ | |||
+ | There's also a page [[Haskell Quiz/FizzBuzz]] with another solution. |
Latest revision as of 15:18, 6 February 2021
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.