Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

remdup predicate need hlep!

Status
Not open for further replies.

vuzu

Programmer
Jan 10, 2010
1
TR
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.
 
You have to travel through the list and add 1 each time, buiding a pair. Your rule will be like that
numbering(+List, +Number, +BuildingList, -FinalList).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top