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.

28 lines
639 B

  1. from itertools import combinations
  2. from z3 import *
  3. solver = Solver()
  4. Colours = Datatype("Colours")
  5. Colours.declare("RED")
  6. Colours.declare("BLUE")
  7. Colours.declare("GREEN")
  8. Colours.declare("YELLOW")
  9. Colour = Colours.create()
  10. f = Function('f', IntSort(), Colour)
  11. variables = list()
  12. for i in range(0,5):
  13. variables.append(Int(f"x{i}"))
  14. solver.add(0 <= variables[-1])
  15. solver.add(variables[-1] <= 5)
  16. solver.add(Distinct(variables))
  17. for combi in combinations(variables,2):
  18. solver.add(Implies(Abs(combi[0] - combi[1]) == 1, f(combi[0]) != f(combi[1])))
  19. result = solver.check()
  20. if result == sat:
  21. print(solver.model())