Created
August 16, 2014 20:14
-
-
Save anonymous/5eff1bb00d4ac7d558ad to your computer and use it in GitHub Desktop.
Pretty FizzBuzz with types and stuff!
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
import Data.List | |
data FizzBuzz = Fizz | Buzz | FizzBuzz | Num Int | |
instance Show FizzBuzz where | |
show Fizz = "Fizz" | |
show Buzz = "Buzz" | |
show FizzBuzz = "FizzBuzz" | |
show (Num n) = show n | |
bzzr :: Int -> FizzBuzz | |
bzzr n | zeroMod 15 = FizzBuzz | |
| zeroMod 3 = Fizz | |
| zeroMod 5 = Buzz | |
| otherwise = Num n | |
where | |
zeroMod x = mod n x == 0 | |
main :: IO () | |
main = print $ intercalate ", " $ map (show . bzzr) [1..100] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment