Last active
April 6, 2020 18:42
-
-
Save gutierri/1c3ff72dbf477b24b1ee5f1ce8ee11d6 to your computer and use it in GitHub Desktop.
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
(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) |
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
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