Skip to content

Instantly share code, notes, and snippets.

@davenportw15
Last active August 29, 2015 14:26
Show Gist options
  • Save davenportw15/f1190077f5a9c430c814 to your computer and use it in GitHub Desktop.
Save davenportw15/f1190077f5a9c430c814 to your computer and use it in GitHub Desktop.
A FizzBuzz implementation in one line of Haskell
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