I've looked through the forum but this problem seems unique. I'm trying to remove the contents of one list from another. For instance:
removed([1,2,3],[2],X).
should give the result X = [1,3]?
So far the code I have come up with is as follows:
removed(L,[],L).
removed([H|T],[H|S],T) :- removed(T,S,T).
This works only for the first element in the list, and I think I need another remove definition to traverse through elements whose heads are not the same, but that part I can't figure out.
removed([1,2,3],[2],X).
should give the result X = [1,3]?
So far the code I have come up with is as follows:
removed(L,[],L).
removed([H|T],[H|S],T) :- removed(T,S,T).
This works only for the first element in the list, and I think I need another remove definition to traverse through elements whose heads are not the same, but that part I can't figure out.