Skip to content

Instantly share code, notes, and snippets.

@patrickbucher
Created February 19, 2022 15:55
Show Gist options
  • Save patrickbucher/9e1e92c911ec9dad760d3f033ac2ce27 to your computer and use it in GitHub Desktop.
Save patrickbucher/9e1e92c911ec9dad760d3f033ac2ce27 to your computer and use it in GitHub Desktop.
Finding the optimal choice for everybody.
:- use_module(library(clpr)).
alice(apple, 1).
alice(banana, 2).
alice(orange, 3).
alice(kiwi, 4).
bob(apple, 1).
bob(orange, 2).
bob(banana, 3).
bob(kiwi, 4).
claire(orange, 1).
claire(apple, 2).
claire(banana, 3).
claire(kiwi, 4).
daniel(banana, 1).
daniel(apple, 2).
daniel(orange, 3).
daniel(kiwi, 4).
unique([]).
unique([_]).
unique([H|T]) :-
\+ (memberchk(H, T)),
unique(T).
choice(A, B, C, D) :-
alice(A, P1),
bob(B, P2),
claire(C, P3),
daniel(D, P4),
unique([A, B, C, D]),
{Penalty = P1 + P2 + P3 + P4},
print(Penalty),
minimize(Penalty).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment