Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2 Use Z 3 to find a solution We are going to reduce your puzzle to a satisfiability problem and solve it using Z 3
Use Z to find a solution
We are going to reduce your puzzle to a satisfiability problem and solve it using Z Basically,
our existential claim will be This puzzle is solvable and then the model that Z produces
to prove the claim will be the solution to the puzzle. To do this, we need to represent the
puzzle as a set of variables and constraints.
The specific steps below are just one suggested way of accomplishing this task; feel free to
do it differently especially if you arent creating a Ciphered Skyscrapers as long as you end
up with an appropriate artifact to turn in see end of the section I recommend frequently
checking your work in progress by using the checksat and getmodel commands. For
example, after the first step below, Z can already tell you that your puzzle is solvable
sat and give you a model solution though since you havent added any constraints yet
that solution will be something silly like putting a into every square.
Create variables representing all the things that the solver must determine: one variable for each square in the grid its probably best to also include squares that already have a clue written in them, even though theres nothing further for the solver to determine and one variable for each letter used by your cipher. You can use whatever variable scheme you want, but if you are using rowcolumn indices anyway and your representation makes the following convenient, please follow standard puzzle convention where row index comes before col index and is the upperleft corner of the grid. So eg the variable for the lowerleft corner might be something like x
Add constraints representing the rules that must be followed even if the grid has no clues given in it for example, in each row all squares must have distinct values
Write a function named clue which takes in three numbers representing the contents of a row or column and returns the appropriate Skyscrapers clue for that rowcolumnFor example, clue should return
Using your clue function when needed, add constraints for each clue given in your puzzle. If you havent actually constructed a puzzle yet, this is one place you can get Z to help you do so: experiment with adding clues and their corresponding constraints one at a time, and for each one, run Z to make sure that your new version of the puzzle still has a solution.
Use Z to confirm your solution is unique
Your goal now is to add one additional assert statement representing the solution is not the
same as the solution found in part This will be a very large constraint tedious to write
by hand, but fast if you use take the model output by part and edit it using findreplace
Assuming your puzzle actually has only one solution, Z should now respond with unsat
since there does not exist a solution which meets all your part constraints while also being
distinct from your part solution. If your puzzle does have multiple solutions, you need to
go back to earlier stages and add more clues constraints to your puzzle until all but one of
the solutions becomes invalid and Zs output will help you do this, since it will provide you
with concrete alternate solutions you may not have thought of Hint: make sure that your
new constraint disallows only the one solution from part rather than encoding a stricter
criterion like the solution doesnt have even one square in common with the solution found
in part There may not be an easy way to check if you did this right, since disallowing a
larger set of solutions would also result in an unsat output.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started