I have a problem.
Define the relation
subsum(Set,Sum,Subset)
such that Set is a multiset of numbers expressed using lists, Subset is a subset of Set, and Sum is the union of the elements of Subset. The following results are obtained.?- subsum([1,2,5,3,2],5,Sub). Sub = [1, 2, 2] ; Sub = [2, 3] ; Sub = [5] ; Sub = [3, 2] ; false. ?-
The answers must not use any relationship other than the answer.
My answer is:
subsum([], 0 ,[]).
subsum([_ | Xs], Sum, Ys) :- subsum(Xs, Sum, Ys).
subsum([X | Xs], Sum, [X | Ys]) :- subsum(Xs, Sum - X, Ys).
But this code does not work as I expected. Could you give me some hints?