Remove unique elements only
There are many resources on how to remove duplicates and similar issues but I can't seem to be able to find any on removing unique elements. I'm using SWI-Prolog but I don't want to use built-ins to achieve this. That is, calling remove_unique([1, 2, 2, 3, 4, 5, 7, 6, 7], X). should happily result in X = [2, 2, 7, 7] . The obvious solution is as something along the lines of count(_, [], 0) :- !. count(E, [E | Es], A) :- S is A + 1, count(E, Es, S). count(E, [_ | Es], A) :- count(E, Es, A). is_unique(E, Xs) :- count(E, Xs, 1). remove_unique(L, R) :- remove_unique(L, L, R). remove_unique([], _,