Encoding
The puzzle is encoded into text then a script is used to generate the underlying logic of the puzzle. These logic lines are then passed to an SMT solver for analysis and resolution. Microsoft's Z3 and MathSAT solvers are used. The thirteen hexagons are fixed across the grid. The clue cell locations can be determined from the encoded input. Single digit integers are used for the input with 0 for unknown and number for a clue cell.Puzzle Logic
Fig 1: Number Workout grid showing yellow spots on boundary cell pairs |
This puzzle resembles Hidato for a neighbour cell constraints and Sudoku for the region values constraints. However the hexagon grid layout and boundary neighbour cells equality constraints make this puzzle unique.
Neighbouring boundary cells
Three possible methods for identifying boundary cells were considered :- Geometry - Each cell position is calculated and when the distance between any two cells is a specific value they would be declared as neighbour cells.
- Cell region map - The grid is fixed and the input cell order is fixed therefore an input map could be used to identify cell pairs.
- Counting - If the cells are counted in rows (from one) then these rules would identify the cell pairs:
- "The third and forth cell on each row" and
- "The sixth and seventh cell on each row" and
- "The fifth cell on even rows is the pair of the fifth cell on the next row down" and
- "The second and eighth cells on odd rows are paired with the same cells on the next row"
Building SMT-LIB file
Displaying the output
The usual technique of reading the solver output back into the logic generation script for display and checking is used. However the output generation for this puzzle varies from a standard rectangular grid as used by Sudoku, Hidato and similar puzzles. For this puzzle a different method of placing the results on top of an image of the input grid was required. See appendix below for more details.Fig:2 the solved puzzle, Yellow cells are "First of Pair", Teal are "Last Of Pair" |
#nw nw_003.txt DMWeekend 25 May 2020
Checking Hex Regions =
Region 1 Cells are 0 1 2 5 7 8 OK
Region 2 Cells are 3 4 5 12 13 14 OK
Region 3 Cells are 8 10 11 17 19 20 OK
Region 4 Cells are 7 14 17 23 25 26 OK
Region 5 Cells are 13 21 23 30 31 32 OK
Region 6 Cells are 19 26 29 35 37 38 OK
Region 7 Cells are 25 32 35 41 43 44 OK
Region 8 Cells are 31 39 41 48 49 50 OK
Region 9 Cells are 37 44 47 53 55 56 OK
Region 10 Cells are 43 50 53 59 61 62 OK
Region 11 Cells are 49 57 59 66 67 68 OK
Region 12 Cells are 55 62 65 71 73 74 OK
Region 13 Cells are 61 68 71 75 76 77 OK
Puzzle has is OK Solution successful.
Error checks test
Fig 3: Introducing an error into the solver output to show solution error checking |
Usage for logic preparation script
Usage: NumberWorkout {options} < puzzle.txt or
NumberWorkout {options} -f puzzle.txt < SolverOutput
-v N :Be verbose to level N ( use v=10 for detailed output )
-f puzzle.txt :Puzzle file needed when reading Solver output use STDIN otherwise
Programs reads STDIN looking for either puzzleFile format lines or Solver output lines
If the input is in puzzleFile format the program will generate solver input lines.
If the input is in Solver output lines format the program will expect a -f puzzleFile paremeter.
Using both these input streams program will then generate display .html output.
Game Rules
13 segmented hexagons are stacked with aligned segments. 1..6 must be put in the segments of the hegagons such that where the segemnts are aligned the number in those segments must be the same. No duplicates in a single segment. Edges must match.
Stack of hexagons ..
*
* *
*
* *
*
Encode NumberWorkout puzzle Input as follows, 0 for unknown and clue numbers included.
Error Template violation is given if not 3 or 9 numbers on an input line
$ cat nw_001.txt
#NW_001.txt DM weekend 17 May 2020
501
040000050
100000002
200000003
000000000
400600005
000003006
300200006
060000040
401
OR Process results from solver in the following format
sat
( (V0 9)
(V1 7)
(V2 5)
(V3 3)
....
to generate an html layout as output.
Appendix : Placing tags on an image using CSS formatting
Fig 4 Shows the parts required to build the tags over image web display page.
The style section of the page defines how certain elements are to look. po in yellow box sets the format for a tag. Then c0 to cxx, in red box, define the column positions followed by r0 to rxx the definitions for the row positions.
The image is displayed in the blue box. The tags are then individually placed using the class string built from the above styles. The example in green box "po c3 r3" is positioned at from left 240px and from top 305px.
For the results image the styes py and pb where added along side p0 with definitions that included a different background:colour; definitions.