Skip to content

Instantly share code, notes, and snippets.

@thejsj
Last active August 31, 2016 04:50
Show Gist options
  • Save thejsj/e8f0a25f86f6502dd809e071b20f6e71 to your computer and use it in GitHub Desktop.
Save thejsj/e8f0a25f86f6502dd809e071b20f6e71 to your computer and use it in GitHub Desktop.
FizzBuzz in Haskell
fizzbuzz :: Int -> String
fizzbuzz x | mod x 15 == 0 = "fizzbuzz"
| mod x 5 == 0 = "fizz"
| mod x 3 == 0 = "buzz"
| otherwise = show x
printAll [] = return ()
printAll (x:xs) = putStrLn x >> printAll xs
main = do
print "Number of lines:"
numStr <- getLine
let num = read numStr :: Int
printAll $ map fizzbuzz [0..num]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment