Implement a predicate remdup/2 which removes duplicate elements from a list,
indexes the remaining elements (1 to n), and prints out how many elements there are.
For example,
?- remdup([7,2,4,5,6,7,9,4],X).
There are 6 elements in the list.
X = [[1,7],[2,2],[3,4],[4,5],[5,6],[6,9]]
!! the question is this. what I have done is :
remdup(L, L1) :- remdup(L, [], L1).
remdup([H|T], Xnew, List) :-
member(H, Xnew),
!,
remdup(T, Xnew, List).
remdup([H|T], Xnew, List) :-
remdup(T, [H|Xnew], List).
remdup([], L, L):-
write('There'), write(' '), write('are'), write(' '),
write(N), write(' '), write('elements'), write(' '),
write('in'), write(' '), write('the'), write(' '), write('list').
the remaining part is the indexing part. how could I do that.
indexes the remaining elements (1 to n), and prints out how many elements there are.
For example,
?- remdup([7,2,4,5,6,7,9,4],X).
There are 6 elements in the list.
X = [[1,7],[2,2],[3,4],[4,5],[5,6],[6,9]]
!! the question is this. what I have done is :
remdup(L, L1) :- remdup(L, [], L1).
remdup([H|T], Xnew, List) :-
member(H, Xnew),
!,
remdup(T, Xnew, List).
remdup([H|T], Xnew, List) :-
remdup(T, [H|Xnew], List).
remdup([], L, L):-
write('There'), write(' '), write('are'), write(' '),
write(N), write(' '), write('elements'), write(' '),
write('in'), write(' '), write('the'), write(' '), write('list').
the remaining part is the indexing part. how could I do that.