Skip to content

Instantly share code, notes, and snippets.

@vderyagin
Last active December 11, 2015 09:19
Show Gist options
  • Save vderyagin/4579480 to your computer and use it in GitHub Desktop.
Save vderyagin/4579480 to your computer and use it in GitHub Desktop.
FizzBuzz solution in Haskell
#! /usr/bin/env runhaskell
import Control.Monad (when, unless)
main :: IO ()
main = mapM_ fb [1..100]
fb :: Int -> IO ()
fb n = do
let divBy3 = n `mod` 3 == 0
divBy5 = n `mod` 5 == 0
when divBy3 $ putStr "Fizz"
when divBy5 $ putStr "Buzz"
unless (divBy3 || divBy5) $ putStr . show $ n
putChar '\n'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment