I would like to remove more than one repetition from a previously ordered list in prolog. I would like the output to look like this:
Example 1.
?- remove_dups ([1,1,2,2,3,4,5,5,6], List).
List = [3,4,6]
As you can see, it would remove not a repetition of the same element, but all of it.
I used the following algorithm, I made some modifications but without success. Here is the algorithm I used:
remove_dups([], []).
remove_dups([X], [X]).
remove_dups([X,X|T], [X|R]) :-
remove_dups([X|T], [X|R]).
remove_dups([X,Y|T], [X|R]) :-
X \== Y,
remove_dups([Y|T], R).
remove_dups([X,Y|T], [X|R]) :-
( X == Y
-> remove_dups([Y|T], [X|R])
; remove_dups([Y|T], R)
).
However the output I have with this algorithm is this.
?- remove_dups([1,1,2,2,3,4,5,5,6], List).
List = [1,2,3,4,5,6]
But I would like it to be as in example 1, any tips?