Created
February 4, 2017 15:50
-
-
Save P7h/1a79b21aa1a9a1b17701b99c53b51c84 to your computer and use it in GitHub Desktop.
FizzBuzz in Haskell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- FizzBuzz in Haskell | |
fizzbuzz :: Int -> String | |
fizzbuzz n = if fb /= "" | |
then fb | |
else show n | |
where fb = fizz n ++ buzz n | |
fizz:: Int -> String | |
fizz n | n `mod` 3 == 0 = "Fizz" | |
| otherwise = "" | |
buzz:: Int -> String | |
buzz n | n `mod` 5 == 0 = "Buzz" | |
| otherwise = "" | |
main = do | |
mapM_ (putStrLn) [fizzbuzz x | x <- [1..100]] | |
-- ghc fizzbuzz.hs | |
-- fizzbuzz.exe |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment