Question: Write a Prolog rule for the predicate - elimdup(L1,L2), which eliminates duplicate elements from a list. L1 is a given list of elements, and L2
Write a Prolog rule for the predicate
- elimdup(L1,L2), which eliminates duplicate elements from a list. L1 is a given list of elements, and L2 is used to store the result.
Examples
?- elimdup([1, 3, 5, 3],R).
yes, R = [1, 3, 5]
?- elimdup([1, 3, 5], R).
yes, R = [1, 3, 5]
?- elimdup([a, b, a, c, b], R).
yes, R = [a, b, c]
?- elimdup([a, b, a, c, b, a], R).
yes, R = [a, b, c]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
