Skip to content

Instantly share code, notes, and snippets.

@dav1dddd
Created August 22, 2020 12:19
Show Gist options
  • Save dav1dddd/9b74c90eba1b05da1575faa67469f204 to your computer and use it in GitHub Desktop.
Save dav1dddd/9b74c90eba1b05da1575faa67469f204 to your computer and use it in GitHub Desktop.
haskell fizzbuzz repl.it
-- "::" 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