Last active
August 18, 2024 19:33
-
-
Save rmela/a031f3f3fca92d3b5db1c473bdd3ca94 to your computer and use it in GitHub Desktop.
Solution to frietkot problem
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
# solution to the Frietkot problem https://people.cs.kuleuven.be/~tias.guns/frietkot/ using pysat | |
from pysat.solvers import Solver | |
MAYONNAISE = 1 | |
KETCHUP = 2 | |
CURRY = 3 | |
ANDALOUSE = 4 | |
SAMURAI = 5 | |
nora = [MAYONNAISE, KETCHUP ] | |
leander = [ -SAMURAI , MAYONNAISE ] | |
benjamin = [ -ANDALOUSE , -CURRY , -SAMURAI] | |
behrouz = [KETCHUP , CURRY , ANDALOUSE ] | |
guy = [ -KETCHUP , CURRY , ANDALOUSE ] | |
daan = [ -KETCHUP , -CURRY , ANDALOUSE ] | |
celine = [ -SAMURAI ] | |
anton = [ MAYONNAISE , -CURRY , -ANDALOUSE ] | |
danny = [ -MAYONNAISE , KETCHUP , ANDALOUSE , SAMURAI ] | |
luc = [ -MAYONNAISE , SAMURAI] | |
friends = [ | |
nora, | |
leander, | |
benjamin, | |
behrouz, | |
guy, | |
daan, | |
celine, | |
anton, | |
danny, | |
luc | |
] | |
solver = Solver(name='m22') | |
for friend in friends: | |
solver.add_clause(clause=friend) | |
solver.solve() | |
print(solver.get_model()) | |
# prints -1, 2, -3, 4, -5 -- which is | |
# !mayonnaise, ketchup, !curry_ketchup, andalouse, !samurai |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment