Include non-unique elements only
问题 This question was asked but there are no answers: here. I read the comments and tried to implement in both ways, but there are more problems that I don't understand. I first tried the easy way that doesn't keep original order: list_repeated(L, Ds) :- msort(L, S), sorted_repeated(S, Ds). sorted_repeated([], []). sorted_repeated([X|Xs], Ds) :- first(Xs, X, Ds). first([], _, []). first([X|Xs], X, [X|Ds]) :- more(Xs, X, Ds). first([X|Xs], Y, Ds) :- dif(X, Y), first(Xs, X, Ds). more([], _, []).