すべての学生が特定のコースに出席することを象徴する述語attendsを含む次のファイルがあります(最初の引数:Student_ID、2番目の引数:Course_ID)。
attends(476, c216).
attends(478, c216).
attends(484, c216).
attends(487, c216).
attends(491, c216).
次のような述語関数を作成したいと思います。
function(W1,L,E):-
bagof(C,attends(Y,C), L1),intersect(L1,W1,L),length(L,E).
%W1 : Week-1 (List: contains courses that will be exams on).
%L : List of intersection between students courses and the ones that
% will be exams on that week(W1). (It is returned only for
% debugging, i don't actually need this
% E : INT : Number of courses the student will be examined on the 1st week
ここで、W1 (Week1) は 3 つのコースのリスト (例: W1= [c216,c205,c902]) で、E は学生が試験を受けるコースの数です。
問題は、すべての生徒にバックトラックが発生するため、「;」を押す必要があることです。そのため、生徒ごとに異なる E があります。代わりに、「;」を押すことなく、これらの E 値をすべて 1 つのリストに含めることが必要です。次に、E 値が 2 より大きい (>2) 数を確認します。