Skip to content

Sudoku

All formats · Reader spec · Cases and output

sudoku.iris reads a # size=N box=WxH header followed by an N×N grid. The alphabet 123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0 maps to values 1–36; . maps to 0 for blank cells. Data contains n, box_width, box_height, and cells. Checks require the box area to equal N and every given value to be at most N; solving the puzzle and checking its uniqueness belong to the host.

The format source is the scaled sudoku corpus README. The reader spec is copied verbatim from Gecode’s sudoku-instances.hh.

  • four-by-four uses a 4×4 grid with 2×2 boxes and blank cells.
  • bad-box-size changes the box dimensions to 3×2. The reference reports E-CHECK-FAILED with an empty record path.

The instances statement permits several puzzles in one file; these samples each contain one. These are hand-made samples under the repository’s MIT license. See the library README for case layout, validation, and Gecode notices.

Reader spec

From Gecode commit 5e7bbd5c26b0702c6fd652356b2289da0710ac3c. Source notices.

format sudoku
instances {
line "# size={n:1..} box={box_width:1..}x{box_height:1..}"
cells[n][n]: alphabet "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0" blank "."
check box_width * box_height == n "boxes must tile the grid"
check max(cells) <= n "a value is larger than the size of the grid"
}

Cases and output

Run the commands from the repository root. Successful reads show dzn, JSON, and a summary. Rejected inputs show the CLI's diagnostic and caret, with the stable error code beside it.

bad-box-size

Box dimensions do not tile the grid

# size=4 box=3x2
1..4
.41.
.14.
4..1

E-CHECK-FAILED

check failed: boxes must tile the grid

Read rejectedRun from the repository root.
iris read formats/sudoku/sudoku.iris formats/sudoku/cases/bad-box-size/input.txt --dzn
formats/sudoku/cases/bad-box-size/input.txt:5:5: check failed: boxes must tile the grid
     5 | 4..1
       |     ^
while reading: instance [1]
spec: formats/sudoku/sudoku.iris:7

Input rejected

Download full case · Open in playground

four-by-four

Four-by-four grid with two-by-two boxes

# size=4 box=2x2
1..4
.41.
.14.
4..1
dzn
iris read formats/sudoku/sudoku.iris formats/sudoku/cases/four-by-four/input.txt --dzn
n = 4;
box_width = 2;
box_height = 2;
cells = [| 1, 0, 0, 4
  | 0, 4, 1, 0
  | 0, 1, 4, 0
  | 4, 0, 0, 1 |];
JSON
iris read formats/sudoku/sudoku.iris formats/sudoku/cases/four-by-four/input.txt --json
{"iris":"0.1","entries":[{"name":"n","type":"int","depth":0,"value":4},{"name":"box_width","type":"int","depth":0,"value":2},{"name":"box_height","type":"int","depth":0,"value":2},{"name":"cells","type":"int","depth":2,"value":[[1,0,0,4],[0,4,1,0],[0,1,4,0],[4,0,0,1]]}]}
Summary
iris read formats/sudoku/sudoku.iris formats/sudoku/cases/four-by-four/input.txt --summary
formats/sudoku/cases/four-by-four/input.txt [sudoku]
  n: int 4
  box_width: int 2
  box_height: int 2
  cells: int array 4 x 4

Download full case · Open in playground