Skip to content

Instantly share code, notes, and snippets.

@beastaugh
Created January 24, 2009 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beastaugh/51306 to your computer and use it in GitHub Desktop.
Save beastaugh/51306 to your computer and use it in GitHub Desktop.
FizzBuzz in Haskell; won't win any Code Golf competitions
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
Copy link

unwords[f x|x<-[1..100],let m x y=mod x y==0,let f x|m x 15="fizz buzz"|m x 3="fizz"|m x 5="buzz"|1<2=show x]

@hr-schueler
Copy link

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