Last active
December 11, 2015 09:19
-
-
Save vderyagin/4579480 to your computer and use it in GitHub Desktop.
FizzBuzz solution in Haskell
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
#! /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