Last active
August 29, 2015 14:26
-
-
Save davenportw15/f1190077f5a9c430c814 to your computer and use it in GitHub Desktop.
A FizzBuzz implementation in one line of Haskell
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
mapM_ putStrLn $ map (\x -> case (x `rem` 3, x `rem` 5) of (0, 0) -> "FizzBuzz"; (0, _) -> "Fizz"; (_, 0) -> "Buzz"; (_, _) -> show x) [1..100] | |
-- Alternatively | |
import Data.Function ((&)) | |
[1..100] & map (\x -> case (x `rem` 3, x `rem` 5) of (0, 0) -> "Fizzbuzz"; (0, _) -> "Fizz"; (_, 0) -> "Buzz"; (_, _) -> show x) & mapM_ putStrLn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment