Skip to content

Instantly share code, notes, and snippets.

@achin
Created October 29, 2013 02:59
Show Gist options
  • Save achin/7208540 to your computer and use it in GitHub Desktop.
Save achin/7208540 to your computer and use it in GitHub Desktop.
import Data.List
nums = map (Just . show) [1..]
fizz = cycle [Nothing, Nothing, Just "Fizz"]
buzz = cycle [Nothing, Nothing, Nothing, Nothing, Just "Buzz"]
fb n f b = case (n, f, b) of
(_, Just x, Just y) -> x ++ y
(_, Just x, Nothing) -> x
(_, Nothing, Just y) -> y
(Just n, _, _) -> n
fizzBuzz = zipWith3 fb nums fizz buzz
main = mapM_ putStrLn $ take 100 fizzBuzz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment