Prolog: test list membership without using built in libraries/logic
$10-30 USD
已完成
已发布大约 5 年前
$10-30 USD
货到付款
I need prolog logic that determines if two lists have any elements in common. For example, if I have a list containing numbers [2,4,5,6,8] and a second list containing numbers [1,3,5,6,9] this will return true because they have 5 and 6 in common. However, [1,2,3] and [5,6,8] will return false because there are no common elements between these lists.
ex:
?- similarity([2,4,5,6,8], [1,3,5,6,9]).
true.
?- similarity([1,2,3], [5,6,8]).
false.
NO BUILT IN LOGIC. that includes disjoint, membership, intersection, etc.
I NEED THIS ASAP, BY TOMORROW. thanks.
Hello there! I already implemented what you ask for in swi-prolog, I can give it to you right now. If it's another implementation of Prolog, I have to see if I can convert it, but in principle I should be able to. Hope to hear from you! I'll prove I have it, pasting here the implementation of member/2.
mymember(X, [X|_]) :- !.
mymember(X, [_, T]) :- mymember(X, T).