Write a program in PROLOG to implement remove_dup (L, R) where L denotes the list with some duplicates and the list R denotes the list with duplicates removed.

17.Write a program in PROLOG to implement remove_dup (L, R) where L denotes the list with some duplicates and the list R denotes the list with duplicates removed. 

%PROLOG to implement remove_dup (L, R)

%  below is-member function is not predefined you can use any name as function

is_member(X,[X|_]).
is_member(X,[_|T]):- is_member(X,T).
remove_dups([],[]).
remove_dups([H|T], R):- is_member(H,T), remove_dups(T,R).
remove_dups([H|T],[H|R]):- \+(is_member(H,T)),remove_dups(T,R).


% Output



No comments:

Post a Comment

Featured post

Amazon Interview Process

On July 5, 1994, Jeff Bezos started the world's most "customer-centric" firm out of his garage in Bellevue, Washington. The A...