FizzBuzz: Difference between revisions
Content deleted Content added
m →{{header|zkl}}: tweak |
→{{header|Haskell}}: Added monoidal solution |
||
Line 2,544: | Line 2,544: | ||
main = mapM_ (putStrLn . fizzBuzz) [1..100]</lang> |
main = mapM_ (putStrLn . fizzBuzz) [1..100]</lang> |
||
An elegant solution exploiting monoidal and applicative properties of functions: |
|||
<lang haskell>import Data.Monoid |
|||
fizzbuzz = max |
|||
<$> show |
|||
<*> "fizz" `when` divisibleBy 3 |
|||
<> "buzz" `when` divisibleBy 5 |
|||
<> "quxx" `when` divisibleBy 7 |
|||
where |
|||
when m p x = if p x then m else mempty |
|||
divisibleBy n x = x `mod` n == 0 |
|||
main = mapM_ (putStrLn . fizzbuzz) [1..100]</lang> |
|||
=={{header|HicEst}}== |
=={{header|HicEst}}== |