I am very new to prolog and I was wondering if am on the right approach to my programs specifications. I need to remove the duplicates from a list.
remove_duplicates([],_).
remove_duplicates([X|XS], Y) :-
member(X,Y),
remove_duplicates(XS,Y), !.
remove_duplicates([X|XS], Y) :-
\+member(X,Y),
remove_duplicates(XS,[Y|X]), !.
I have this so far and it works but I was wondering how I can use my program to confirm stuff like:
remove_duplicates([5,4,4,2,2], [5,4,2]).
and it will return true.
Thank you
remove_duplicates([],_).
remove_duplicates([X|XS], Y) :-
member(X,Y),
remove_duplicates(XS,Y), !.
remove_duplicates([X|XS], Y) :-
\+member(X,Y),
remove_duplicates(XS,[Y|X]), !.
I have this so far and it works but I was wondering how I can use my program to confirm stuff like:
remove_duplicates([5,4,4,2,2], [5,4,2]).
and it will return true.
Thank you