Skip to content

Instantly share code, notes, and snippets.

@ShinNoNoir
Created May 15, 2015 16:28
Show Gist options
  • Select an option

  • Save ShinNoNoir/41a46293475a4fb6024e to your computer and use it in GitHub Desktop.

Select an option

Save ShinNoNoir/41a46293475a4fb6024e to your computer and use it in GitHub Desktop.
Just another convoluted way of computing FizzBuzz
-- 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