Difference between revisions of "Haskell Quiz/FizzBuzz/Solution Mikbe"
< Haskell Quiz | FizzBuzz
Jump to navigation
Jump to search
Tomjaguarpaw (talk | contribs) (Removing very old page) |
m (Reverted edits by Tomjaguarpaw (talk) to last revision by Mikbe) |
||
Line 1: | Line 1: | ||
+ | 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 where |
||
+ | |||
+ | main :: IO () |
||
+ | main = do |
||
+ | mapM_ (putStrLn) [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) |
||
+ | </haskell> |
Latest revision as of 15:18, 6 February 2021
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) [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)