Find a element of a list in a another list in Prolog?

As you accept both P1 and P2 as inputs, I suggest to break down both P1 and P2 by their structures to do recursion. One solution could be finding all team of a specific player and finding all players playing for a specific team.

As you accept both P1 and P2 as inputs, I suggest to break down both P1 and P2 by their structures to do recursion. One solution could be finding all team of a specific player and finding all players playing for a specific team: find1(T, L) :- player(T, L). Find1(T|Ts, L) :- player(T, L0), find1(Ts, L1), intersection(L0, L1, L).

Find2(L, P) :- findall(X, (player(X, Y), member(P, Y)), L). Find2(L, P|Ps) :- findall(X, (player(X, Y), member(P, Y)), L0), find2(L1, Ps), intersection(L0, L1, L). Find(X, Y) :- is_list(X), find1(X, Y).

Find(X, Y) :- is_list(Y), find2(X, Y). Hope it helps you somehow.

Find(T, L) :- player(T, L),!. Find(T|Ts, L2) :- player(T, L0), find(Ts, L1), intersection(L0, L1, L2). Thanks a lot pad.. but I cannot run the this part.. when my goal i.e.

Find(milan,X) program failed like in a infinite loop.. by the way.. "! " is this a break code?.. I am not allowed to use this... Is possible to write this without "! "?

– Palindrom May 3 at 15:27 "! " is the cut predicate, it is used to avoid backtracking when a solution is already found. I have updated the code to remove "!", it should work by now.

– pad May 3 at 21:06 Thanks a lot pad... Moreover, How can I do that: if my goal find(X,Y). Can it return like: X=milan , Y=seedorf,zambrotta,gattuso); X=milan,inter , Y=seedorf,zambrotta; X=milan,inter,realmadrid , Y=seedorf; false. I try to do it with: find(X,Y):-not(is_list(X)),not(is_list(Y))..... but I failed to continue.. – Palindrom May 5 at 21:00.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions