I would like to take an L1 list, a list of L2 lists. true if:L1 is a list of numberL2 is a list of list where the sum is a certain number, for example 20, from 0 to i, and the list i + 1 is the remainder.example:partition20 ([12, 11, 7,3,18,1,2], [[12,7,1], [18,2], [11,3]])
On 27/06/2018, at 11:05, Checco7 <pefs...@gmail.com> wrote:how can I partition a list into a list?example sublists who have sum 4:list [1,3,4,2,2] produces [[1,3], [4], [2,2]]
I tried a lot but I did not succeed.
Thanks if you help me
On Jun 28, 2018, at 3:13, Checco7 <pefs...@gmail.com> wrote:
I would like to take an L1 list, a list of L2 lists. true if:L1 is a list of numberL2 is a list of list where the sum is a certain number, for example 20, from 0 to i, and the list i + 1 is the remainder.example:partition20 ([12, 11, 7,3,18,1,2], [[12,7,1], [18,2], [11,3]])my test:sum([],0).sum([X],X).sum([X,Y|Xs],S):-sum([Y|Xs],S1),S is X + S1.
resto([], [], []).
rest([A|Ra], [A|Rb], Z) :-rest(Ra, Rb, Z).rest([A|Ra], Rb, [A|Z]) :-rest(Ra, Rb, Z).partition([], []).partition([A|Ra], [[A|Rb]|Rest]) :-rest(Ra, Rb, Z),partition(Z, Rest),sum([A|Rb],20).
--
You received this message because you are subscribed to the Google Groups "SWI-Prolog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swi-prolog+...@googlegroups.com.
Visit this group at https://groups.google.com/group/swi-prolog.
For more options, visit https://groups.google.com/d/optout.
On Jun 28, 2018, at 3:16, Checco7 <pefs...@gmail.com> wrote: