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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Operations on lists. 1

Status
Not open for further replies.

Kat55

Programmer
Jun 21, 2003
1
AU
Remove the second and succeeding adjacent duplicates.

So that [a,a,a,b,b,c] should become [a,b,c].

Can someone please help me. I have an assignment due and i just don't have a clue. I'm trying to start by checking if the first element is a member of the rest of the tail of the list. But i'm not sure what to do next.

listt([],[]).
listt([H|T],[R]):-
member(H,T),
????.

member(X, [X|Head]).
member(X, [Head|Tail]) :- member(X, Tail).
 
I hi think this might be what you are looking for:

lts([],[]).
lts([H|T1],[H|T2]) :-
not(member(H,T1)),
lts(T1,T2).
lts([H|T1],T2) :-
member(H,T1),!,
lts(T1,T2).

by the way i would define the member/2 predicate like that so you dont get singelton variable warnings:

member(H,[H|_]).
member(H,[_|T]) :-
member(H,T).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top