Re:The Fastest FizzBuzz in the West
by wz1000 on Wednesday August 31, 2016 @06:55AM
(#12397343)
> Fizzbuzz is one of those problems where there's really no clever hidden golfy solution better than the plain old first-reaction naive approach: an iteration with if/elsif/elsif/else.
There is if you exploit that monoid homomorphisms exist from any monoidal type to both the Optional and Function types.
My favourite solution is this:
let (m ~> str) x = str <$ guard (x `mod` m == 0)
in map (fromMaybe . show <*> 3 ~> "fizz" <> 5 ~> "buzz") [1..100]
This is extensible because you can stick as many rules as you want in there, or even factor them out and make it a function
There is if you exploit that monoid homomorphisms exist from any monoidal type to both the Optional and Function types.
My favourite solution is this:
This is extensible because you can stick as many rules as you want in there, or even factor them out and make it a function