Skip to content

Instantly share code, notes, and snippets.

@sarkologist
Last active November 23, 2022 13:10
Show Gist options
  • Save sarkologist/96c2869d1ace78f4f4938f65acba2d7a to your computer and use it in GitHub Desktop.
Save sarkologist/96c2869d1ace78f4f4938f65acba2d7a to your computer and use it in GitHub Desktop.
FizzBuzz in Haskell
import Control.Monad
fizz x = if mod x 3 == 0 then "Fizz" else ""
buzz x = if mod x 5 == 0 then "Buzz" else ""
zzzz x = if mod x 3 /= 0 && mod x 5 /= 0 then show x else ""
main = do
let results = map (fizz <> buzz <> zzzz) [1..30]
mapM_ print $ zip [1..] results
(1,"1")
(2,"2")
(3,"Fizz")
(4,"4")
(5,"Buzz")
(6,"Fizz")
(7,"7")
(8,"8")
(9,"Fizz")
(10,"Buzz")
(11,"11")
(12,"Fizz")
(13,"13")
(14,"14")
(15,"FizzBuzz")
(16,"16")
(17,"17")
(18,"Fizz")
(19,"19")
(20,"Buzz")
(21,"Fizz")
(22,"22")
(23,"23")
(24,"Fizz")
(25,"Buzz")
(26,"26")
(27,"Fizz")
(28,"28")
(29,"29")
(30,"FizzBuzz")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment