Cassandra
Cassandra

Reputation: 217

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)?

Upvotes: 0

Views: 160

Answers (1)

David Tonhofer
David Tonhofer

Reputation: 15316

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

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

Upvotes: 1

Related Questions