Created
August 22, 2020 12:19
-
-
Save dav1dddd/9b74c90eba1b05da1575faa67469f204 to your computer and use it in GitHub Desktop.
haskell fizzbuzz repl.it
This file contains 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
-- "::" has type | |
fizz :: Int -> String | |
-- "|" pipe | |
-- If incremented in 15, 3 or 5 have this text | |
-- otherwise show number instead :^) | |
fizz n | n `mod` 15 == 0 = "FizzBuzz" | |
| n `mod` 3 == 0 = "Buzz" | |
| n `mod` 5 == 0 = "Fizz" | |
| otherwise = show n | |
-- main has type IO() | |
main :: IO() | |
main = mapM_ putStrLn $ map fizz [1..20] | |
{-| | |
This will print: | |
1 | |
2 | |
Buzz | |
4 | |
Fizz | |
Buzz | |
7 | |
8 | |
Buzz | |
Fizz | |
11 | |
Buzz | |
13 | |
14 | |
FizzBuzz | |
16 | |
17 | |
Buzz | |
19 | |
Fizz | |
-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment