1 2 3 4 5 6 7 8 9 10 11
|
%unique(List, Result)
unique([], []). %an empty list does not have repeated elements
unique([First|List], [First|Result]) :-
killall(First, List, Deleted),
unique(Deleted, Result).
%killall( Element, List, Result )
%Result is the List without Element
killall(_, [], []). %an empty list does not have the element
killall( X, [X|List], Result ) :- killall( X, List, Result ). %The element is at the top,
killall( X, [Y|List], [Y|Result] ) :- Y=/=X, killall( X, List, Result ).
|