[Haskell-cafe] How to dynamic plan in Haskell?

Francesco Ariis fa-ml at ariis.it
Sat May 18 05:48:18 UTC 2019


Hello,

On Sat, May 18, 2019 at 12:33:00PM +0800, Magicloud Magiclouds wrote:
> I solved the question. But I could not figure out a FP style solution.
> 
> Question:
> 
> 1 - 9, nine numbers. Show all the possible combinations that sum up to
> 10. Different orders are counted as the same.

A possible solution takes advantage of powersets with the [] Monad.

    λ> :m +Control.Monad
    λ> f cs = filterM (\x -> [True, False]) cs
    λ> filter ((==10) . sum) (f [1..10])



More information about the Haskell-Cafe mailing list