I have a function that computes the intersection of two list in prolog. code:
list_member(X,[X|_]).
list_member(X,[_|TAIL]) :- list_member(X,TAIL).
list_intersect([X|Y],Z,[X|W]) :-
list_member(X,Z), list_intersect(Y,Z,W).
list_intersect([X|Y],Z,W) :-
\+ list_member(X,Z), list_intersect(Y,Z,W).
list_intersect([],_,[]).
I want a function that returns true if the intersection list provided by the above fn is empty else it should return false.
Code tried:
success_fn([X], [Y]) :-
list_intersect(X, Y, Z),
length(Z, L),
L > 0, write('False');
L < 1, write('True').
Query I used:
success([1,2,3,4,5,6], [1, 2, 3]).
The output returns false every time.