Last active
December 24, 2022 01:14
-
-
Save Dietr1ch/9881fdc142e8bc22590c048376c8ae6f to your computer and use it in GitHub Desktop.
Secret santa assignment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use_nix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
person( | |
alice; | |
bob; | |
carol; | |
dave; | |
eve). | |
are_family( | |
bob, carol; | |
carol, dave). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
time_clingo: secret_santa.lp input.lp | |
time \ | |
clingo \ | |
--models '0' \ | |
--opt-mode 'optN' \ | |
secret_santa.lp \ | |
input.lp | |
time_python: | |
time python -c 'exit' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Secret Santa assignment | |
% Generators | |
% ---------- | |
% Everyone gives a single gift. (Each gifter must give a single gift) | |
1 { gives(Gifter, Giftee) : person(Giftee) } 1 :- | |
person(Gifter). | |
% Everyone receives a single gift. (Each giftee must receive a single gift) | |
1 { gives(Gifter, Giftee) : person(Gifter) } 1 :- | |
person(Giftee). | |
% Restrictions | |
% ------------ | |
% Hard restrictions: | |
% * There must be at least 4 people. Solutions are not so secret otherwise. | |
:- { person(_) } < 4. | |
% * You can't give gifts to yourself. | |
:- gives(P, P). | |
% Soft restrictions: | |
#const penalty = 1. | |
% * Avoid giving gifts to family members. | |
:~ gives(P1, P2), are_family(P1, P2). [penalty,P1,P2] | |
are_family(P, P) :- | |
person(P). | |
are_family(P1, P2) :- | |
are_family(P2, P1). | |
are_family(P1, P2) :- | |
person(P1), | |
person(P2), | |
person(P), | |
are_family(P, P1), | |
are_family(P, P2). | |
% Misc | |
% ---- | |
% Only show `gives(A, B)`. | |
#show gives/2. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let | |
pkgs = import <nixpkgs> {}; | |
in | |
{ | |
programmeEnv = pkgs.stdenv.mkDerivation { | |
name = "Secret_Santa"; | |
buildInputs = with pkgs; [ | |
clingo | |
gnumake | |
]; | |
}; | |
} |
Author
Dietr1ch
commented
Dec 23, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment