I found this old question ( Prolog Predicate to return true when two people have same hobby ) for writing some code to find the same hobby between two persons using dif. I have a similar situation, to display the names of two persons that have the same hobbies,but the hobbies element is defined as a list. Whatever I try it doesn't seem to work, any ideas would be appreciated.
This is what I have so far:
one_common_hobby(P1,P2):-
dif(P1,P2),
person(P1,_,_,hobbies([H|Tail])),
person(P2,_,_,hobbies([H|Tail])),
member(P1,Tail),
member(P2,Tail).
For simplicity, suppose the predicate
personis defined as follows:To find two different persons (
P1andP2) who have a common hobby you must:H1).H2).Xthat belongs simultaneously to listsH1andH2.Example: