Subject: Re: [SWIPL] Prolog

From: Rastei Amelia Viorela <[email-masked]>
Date: Mon, 18 Dec 2000 17:20:53 +0200 (EET)

On Mon, 18 Dec 2000, Nuno Baptista wrote:

> I'm trying to find the algorithm to find if there are equal elements in to given lists. 

 Like L1=[4,3,5,4,2] is equal to L2=[3,2,4,5,4]??

> I could use some help in this task.
 If so this predicate will work:

 equal_lists([H1|T1],L2):- select(L2,H1,Res),equal_lists(T1,Res).
 equal_lists([],[]).        

Try on:

  ?- equal_lists([3,4,2,3,1],[2,1,3,3,4]).

  Yes
  ?- equal_lists([3,4,2,3,1],[2,1,3,4]).

  No

> Thanks!!!

 You are welcome!  
> 
> Here is the code :
> 
> lista([],[],L):-!.
> lista([H1|T1],L,R):-
> 	member(H1,L),
> 	lista([H1|T1],L,[H1|R]).
> lista([H1|T1],[H2|T2],L):-
> 	lista(T1,T2,L).
> 
> Herege doesn't suffer from insanity. He enjoys every minute of it.
>                                        
>                                    *****HEREGE*****
> 
> 
> 
> ----------------
> * To UNSUBSCRIBE, please use the HTML form at
> 
>     http://www.swi.psy.uva.nl/projects/SWI-Prolog/index.html#mailinglist
> 
> or send mail to [email-masked] using the Subject: "unsubscribe"
> (without the quotes) and *no* message body.
> 
> ** An ARCHIVE of this list is maintained at
> 
>     http://www.swi.psy.uva.nl/projects/SWI-Prolog/mailinglist/archive/
> 

-- 

 Amelia Rastei,
 Dept. Computer Science,
 Babes Bolyai University,
 Cluj Napoca, Romania.