Created
May 18, 2013 23:55
-
-
Save fgaray/5606145 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
data FizzBuzz = Number Int | |
| Fizz | |
| Buzz | |
| FizzBuzz | |
instance Show FizzBuzz where | |
show (Number n) = show n | |
show Fizz = "Fizz" | |
show Buzz = "Buzz" | |
show FizzBuzz = "Fizz Buzz" | |
fizzbuzz :: [FizzBuzz] | |
fizzbuzz = map fizzbuzz' [1..100] | |
where | |
fizzbuzz' :: Int -> FizzBuzz | |
fizzbuzz' n | |
| n `mod` 15 == 0 = FizzBuzz | |
| n `mod` 3 == 0 = Fizz | |
| n `mod` 5 == 0 = Buzz | |
| otherwise = Number n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment