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

Magicloud Magiclouds magicloud.magiclouds at gmail.com
Sat May 18 14:13:21 UTC 2019


Thanks. This is kind like my original (did not get through) thought.

On Sat, May 18, 2019 at 8:25 PM Thorkil Naur <naur at post11.tele.dk> wrote:
>
> Hello,
>
> On Sat, May 18, 2019 at 12:33:00PM +0800, Magicloud Magiclouds wrote:
> > ...
> > 1 - 9, nine numbers. Show all the possible combinations that sum up to
> > 10. Different orders are counted as the same.
> >
> > For example, [1, 4, 5].
>
> With
>
>   sumIs n [] = if n == 0 then [[]] else []
>   sumIs n (x:xs)
>     = (if n < x then
>         []
>       else
>         map (x:) $ sumIs (n-x) xs
>       )
>       ++ sumIs n xs
>
> we can do:
>
> Prelude Main> sumIs 10 [1..9]
> [[1,2,3,4],[1,2,7],[1,3,6],[1,4,5],[1,9],[2,3,5],[2,8],[3,7],[4,6]]
>
> > ...
>
> Best
> Thorkil


More information about the Haskell-Cafe mailing list