Skip to content

Instantly share code, notes, and snippets.

@gutierri
Last active April 6, 2020 18:42
Show Gist options
  • Save gutierri/1c3ff72dbf477b24b1ee5f1ce8ee11d6 to your computer and use it in GitHub Desktop.
Save gutierri/1c3ff72dbf477b24b1ee5f1ce8ee11d6 to your computer and use it in GitHub Desktop.
(defn fizzbuzz [start finish]
(map (fn [n]
(cond
(zero? (mod n 15)) "FizzBuzz"
(zero? (mod n 3)) "Fizz"
(zero? (mod n 5)) "Buzz"
:else n))
(range start finish)))
(fizzbuzz 1 100)
module Main where
main :: IO ()
main = printAll $ map fizzBuzz [1..100]
where
printAll [] = return ()
printAll (x:xs) = putStrLn x >> printAll xs
fizzBuzz :: Integer -> String
fizzBuzz n | n `mod` 15 == 0 = "FizzBuzz"
| n `mod` 5 == 0 = "Fizz"
| n `mod` 3 == 0 = "Buzz"
| otherwise = show n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment