Skip to content

Instantly share code, notes, and snippets.

@challengee
Created June 7, 2020 21:10
Show Gist options
  • Save challengee/f13241dfd3a2489dec5d92f222467279 to your computer and use it in GitHub Desktop.
Save challengee/f13241dfd3a2489dec5d92f222467279 to your computer and use it in GitHub Desktop.
% reply(Question, Person, Reply).
% replies are loaded externally.
% Set of questions/persons.
question(Q) :- reply(Q,_,_).
person(P) :- reply(_,P,_).
% Form a cluster of questions.
0 { cluster(Q) } 1 :- question(Q).
% Check if a person replied as expected to a question in the cluster.
% If the question is in the cluster, the reply must be positive.
expected(Q,P) :- reply(Q,P,1), cluster(Q).
% If it's not, the reply does not matter.
expected(Q,P) :- reply(Q,P,_), not cluster(Q).
% When a person replies positive to all questions
% in the cluster, the person is a perfect fit.
fit(P) :- person(P), expected(Q,P) : question(Q).
% A cluster scores 1 point for each fit person,
% multiplied by the amount of questions in the cluster.
% We try to maximize this score.
#maximize { 1,Q,P : fit(P), cluster(Q) }.
% Cluster must be non-empty.
:- 0 { cluster(Q) } 0.
#show cluster/1.
#show fit/1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment