Skip to content

Instantly share code, notes, and snippets.

@programaths
Created June 22, 2016 20:18
Show Gist options
  • Save programaths/7c598608fda2dc4fc42fb2c3eaab82dd to your computer and use it in GitHub Desktop.
Save programaths/7c598608fda2dc4fc42fb2c3eaab82dd to your computer and use it in GitHub Desktop.
-- V1
[ if x `mod` 3 == 0 then
"Fizz"
else
if x `mod` 5 == 0 then
"Buzz"
else
if x `mod` 15 == 0 then
"FizzBuzz"
else show x
| x <- [1..16] ]
-- V2
fizzBuzz :: Int -> String
fizzBuzz n
| mult15 = "FizzBuzz"
| mult3 = "Fizz"
| mult5 = "Buzz"
| otherwise = show n
where mult15 = n `mod` 15 == 0
mult5 = n `mod` 5 == 0
mult3 = n `mod` 3 == 0
map fizzBuzz [1..16]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment