Skip to content

Instantly share code, notes, and snippets.

@regularcoder
Created May 19, 2013 07:53
Show Gist options
  • Save regularcoder/5607003 to your computer and use it in GitHub Desktop.
Save regularcoder/5607003 to your computer and use it in GitHub Desktop.
FizzBuzz in Haskell
--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