Created
May 19, 2013 07:53
-
-
Save regularcoder/5607003 to your computer and use it in GitHub Desktop.
FizzBuzz in Haskell
This file contains hidden or 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
--Tells us if x is divisible by y | |
divby :: (Integral x) => x -> x -> Bool | |
divby x y = | |
(x `mod` y) == 0 | |
--Internal function that returns output for a single number | |
isfizzbuzz :: (Integral x) => x -> String | |
isfizzbuzz x | |
| divby x 3 && divby x 5 = "FizzBuzz" | |
| divby x 3 = "Fizz" | |
| divby x 5 = "Buzz" | |
| otherwise = show x | |
--Method that returns FizzBuzz output on a list of numbers | |
fizzbuzz :: (Integral x) => [x] -> [String] | |
fizzbuzz x = | |
map isfizzbuzz x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment