1
我的数据库包含以下谓词:从数据库中计数
road(1,2,geel)。 路(2,3,blauw)。 道路(1,3,geel)。
其中前2个数字是点。我必须检查每一个点的道路数量。我设法用下面的代码来做到这一点,但不知何故,我认为有一个更好的方法来做到这一点。
% Count(Element, List, Occurences) => Counts the amount of occurences of Element in the given List
count(_, [], 0).
count(X, [X | T], N) :-
!, count(X, T, N1),
N is N1 + 1.
count(X, [_ | T], N) :-
count(X, T, N).
checkRoad :-
findall(Point,(weg(Point,_,_) ; weg(_,Point,_)),List),
list_to_set(List,K),
foreach((member(P,K), count(P, List,N)), N mod 2 =:= 0).
这很有道理,谢谢:) – user757926