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.

48 lines
1.1 KiB

7 months ago
  1. \item \lect Complete the following python script with the necessary statements.
  2. The final script should map each integer of a list of five integers to four possible colours such that the mapping returns different colours for adjacent integers.
  3. % You need to declare and populate a z3 \texttt{Datatype}
  4. % Furthermore, you need to create a list of five distinct integers and bound them.
  5. % Finally, enforce the constraints on the uninterpreted function ....
  6. \begin{pythonSourceCode}
  7. from itertools import combinations
  8. from z3 import *
  9. solver = Solver()
  10. # Declare a Datatype and populate it with 4 colours.
  11. # Declare a function from integers to your custom datatype
  12. variables = list()
  13. for i in range(0,5):
  14. variables.append(Int(i))
  15. # Bound each integer i such that 0 <= i < 5
  16. # Enfore that all i are distinct
  17. # Enforce that colours are different for adjacent integers
  18. for combi in combinations(variables,2):
  19. result = solver.check()
  20. if result == sat:
  21. print(solver.model())
  22. \end{pythonSourceCode}