Last active
August 29, 2015 14:05
-
-
Save ryantm/b1dd9218e2a391e1e2db to your computer and use it in GitHub Desktop.
Haskell Fizzbuzz
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
newtype FizzBuzz = FizzBuzz Int | |
instance Show FizzBuzz where | |
show (FizzBuzz i) | |
| iDivisibleBy 15 = "Fizz Buzz" | |
| iDivisibleBy 5 = "Buzz" | |
| iDivisibleBy 3 = "Fizz" | |
| otherwise = show i | |
where | |
iDivisibleBy n = i `rem` n == 0 | |
main :: IO () | |
main = print $ take 15 (map FizzBuzz [1..]) |
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
fizzBuzz :: Integer -> String | |
fizzBuzz i | |
| iDivisibleBy 15 = "Fizz Buzz" | |
| iDivisibleBy 5 = "Buzz" | |
| iDivisibleBy 3 = "Fizz" | |
| otherwise = show i | |
where | |
iDivisibleBy n = i `rem` n == 0 | |
main :: IO () | |
main = print $ take 15 (map fizzBuzz [1..]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment