Toggle navigation
?
users online
Logout
Open hangout
Open chat for current file
% See https://buttondown.com/hillelwayne/archive/a48fce5b-8a05-4302-b620-9b26f057f145/ :- use_module(library(dif)). % Sound inequality :- use_module(library(clpfd)). % Finite domain constraints % The student's test score % score(student answers, answer key, score) score([], [], 0). score([A|As], [A|Ks], N) :- N #= M + 1, score(As, Ks, M). score([A|As], [K|Ks], N) :- dif(A, K), score(As, Ks, N). % FLip member so we can use it in maplist to type-constrain an answer key contains(L, X) :- member(X, L). % A key that matches all of the student scores. key(Key) :- length(Key, 10), maplist(contains([a,b]), Key), score([b, b, a, b, a, b, b, a, b, b], Key, 7), score([b, a, a, a, b, a, b, a, a, a], Key, 5), score([b, a, a, a, b, b, b, a, b, a], Key, 3). solution(X) :- key(Key), score([b, b, a, a, a, b, b, a, a, a], Key, X). /** <examples> Your example queries go here, e.g. ?- L = [a,B,c], [Y|X] = [1,2|L], B + 1 #= 7. % demos of score ?- score([a, b, b], [b, b, b], 2). ?- score([a, b, b], [b, b, b], X). ?- score(X, [b, b, b], 2). % solutions ?- key(Key). ?- solution(X). ?- findall(X, (key(Key), score([b, b, a, a, a, b, b, a, a, a], Key, X)), L). */