[Haskell-cafe] How to dynamic plan in Haskell?
Magicloud Magiclouds
magicloud.magiclouds at gmail.com
Sat May 18 06:00:49 UTC 2019
I see. Did not got the filterM part in mind. Thanks.
On Sat, May 18, 2019 at 1:48 PM Francesco Ariis <fa-ml at ariis.it> wrote:
>
> 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])
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
More information about the Haskell-Cafe
mailing list