Prolog: splitting a list into two lists (unique items / duplicate items)
问题 I have been trying to split a given list into two different lists: Unique and Duplicate. For example, if we have the list [1, 1, 2, 3, 3, 4, 5] I want the Unique list to be [2, 4, 5] and Duplicate to be [1, 3] . I don't want all the 1's in the list to be in the Duplicate list. I just need one of it. The code I have right now: compareL([_|[]], Unique, Dup). compareL([X3,Y3 | Tail], [X3 | Unique], Dup) :- X3 =\= Y3, compareL([Y3 | Tail], Unique, Dup). compareL([X3,Y3 | Tail], Unique, [X3 | Dup]