Created
January 24, 2009 02:09
-
-
Save beastaugh/51306 to your computer and use it in GitHub Desktop.
FizzBuzz in Haskell; won't win any Code Golf competitions
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
module Main (main) where | |
main :: IO () | |
main = putStr . unlines . take 100 $ fizzBuzz | |
fizzBuzz :: [String] | |
fizzBuzz = map (either show id . fizzes) [1..] | |
fizzes :: Int -> Either Int String | |
fizzes n | 15 `divides` n = Right "FizzBuzz" | |
| 3 `divides` n = Right "Fizz" | |
| 5 `divides` n = Right "Buzz" | |
| otherwise = Left n | |
divides :: Int -> Int -> Bool | |
n `divides` m = m `mod` n == 0 |
rickhanlonii
commented
Nov 27, 2015
rickhalonii, sorry, that's not quite right. In FizzBuzz, a 15 = "FizzBuzz" without the space.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment