Created
May 15, 2015 16:28
-
-
Save ShinNoNoir/41a46293475a4fb6024e to your computer and use it in GitHub Desktop.
Just another convoluted way of computing FizzBuzz
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
| -- convoluted FizzBuzz | |
| import Data.Monoid | |
| import Data.Function (on) | |
| every :: Int -> a -> [Maybe a] | |
| every n x = cycle (replicate (n-1) Nothing ++ [Just x]) | |
| fizzbuzz :: [String] | |
| fizzbuzz = | |
| map (\(First (Just x)) -> x) $ | |
| zipWith ((<>) `on` First) | |
| (foldr1 (zipWith (<>)) [threes, fives]) | |
| nats | |
| where | |
| nats = map (Just . show) [1..] | |
| threes = every 3 "Fizz" | |
| fives = every 5 "Buzz" | |
| main :: IO () | |
| main = mapM_ putStrLn fizzbuzz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment