So I have a predicate:
compatible([],_).
compatible(_,[]).
compatible([HA|TA],[HB|TB]) :-
HA \= HB,
compatible(TA,TB).
It currently takes two lists and determines if they are pairwise compatible returning true if so and false if not.
For example:
?- compatible([8,2,6,3,67],[7,4,7,4,3]).
true
?- compatible([8,2,6,3,3],[7,4,7,4,3]).
false.
The 2nd call returned false because a 3 was in the 5th position of both lists.
My question is how can I modify this predicate so it recursively checks more than 2 lists. Potentially, the predicate could check a list of lists that contains 1,2,3,4,5 or perhaps even infinite lists. It would return false if any of the lists weren't compatible with one another.
Therefore I could check 3 lists like so:
let Y = [[8,2,6,3,67],[7,4,7,4,3],[1,3,42,1,52]]
then...
?- compatible(Y).
true
let Z = [[8,2,6,3,67],[7,4,7,4,3],[1,3,6,1,52]]
then...
?- compatible(Z).
false.
where the 2nd call fails because a 6 was in the 3rd position of list 1 and 3.