Search code examples
listprologartificial-intelligence

Prolog for sets (lists)


I'm learning prolog through youtube videos and I'm struggling a lot with lists. I'm trying to write a predicate overlap(A,B) that will find out if A and B have any common elements. Which I'm able to do but how can I use this overlap(A,B) predicate to define another predicate disjoint(S1, S2)?


Solution

  • If there is no overlap between S1and S2 then S1and S2 are disjoint:

    disjoint(S1,S2) :- \+ overlap(S1,S2).