You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
871 B

  1. # coding: utf-8
  2. from z3 import *
  3. ################################# Burglars ##################################
  4. # create the solver
  5. solver = Solver()
  6. #############################################################################
  7. # (1) Ed: "Fred did it, and Ted is innocent".
  8. # (2) Fred: "If Ed is guilty , then so is Ted".
  9. # (3) Ted: "Im innocent, but at least one of the others is guilty".
  10. #############################################################################
  11. # TODO Create boolean variables for each of the culprits
  12. # TODO Add constraints to the solver representing the statements from above
  13. # Hint: The statement of a culprit should be true if and only if he is not guilty!
  14. res = solver.check()
  15. if res != sat:
  16. print("unsat")
  17. sys.exit(1)
  18. print(solver)
  19. m = solver.model()
  20. for d in m.decls():
  21. print("%s -> %s" % (d, m[d]))
  22. print("\n" + str(m))