我有一个问题,其中我有一个元素列表,我必须循环遍历特定 /2 谓词的所有实例,以查找哪个实例在其列表中具有最多匹配元素。在实施方面,我似乎无法弄清楚我应该如何更新迄今为止的最高匹配,然后在没有更多匹配时停止。
findAnswer(MyList, HighMatchNum,_):-
answer(X,Y),
myIntersection(MyList, Y, NUM), //handles a single instance check and returns how many elements match.
NUM > HighMatchNum,
findAnswer(MyList, NUM, answer(X,Y)).
//Knowledge base
answer(sample1, [a,b,c,d]).
answer(sample2, [d,c,e]).