Skip to content

Nonogram

All formats · Reader spec · Cases and output

nonogram.iris reads the .non subset exported by webpbn: width, height, rows, and columns, with comma-separated clues on one line per row or column. Data contains the dimensions and ragged row and col arrays. A single 0 denotes an empty row or column and remains [0] in the data. Other keyword lines are skipped.

The format source is Steven Simpson’s puzzle-file format, also available through webpbn’s export tool. The reader spec is copied from Gecode’s nonogram.cpp. It requires explicit width and height lines rather than the full format’s dimension aliases columns N and rows N.

  • five-by-five describes a 5×5 X.
  • row-too-wide gives its first row a clue of 6. The reference reports E-CHECK-FAILED with record path [0].

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 nonogram
separators ","
sections skip other {
"width {width:1..}"
"height {height:1..}"
"rows" {
repeat height {
list row: 0.. until eol
}
}
"columns" {
repeat width {
list col: 0.. until eol
}
}
}
check height <= 1000000 / width "the board must have at most a million fields"
check size(row) == height && size(col) == width
"the numbers of rows and columns differ from the board size"
check count(row) <= 1 || min(row) > 0 "a 0 must be the only clue of its row"
check count(col) <= 1 || min(col) > 0 "a 0 must be the only clue of its column"
check sum(row) + count(row) - 1 <= width "the clues of a row do not fit into the width of the board"
Excerpt · View full reader spec

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.

five-by-five

Five-by-five X with comma-separated clues

title "Hand-made X"
width 5
height 5
rows
1,1
1,1
1
1,1
1,1
columns
1,1
1,1
1
1,1
1,1
dzn
iris read formats/nonogram/nonogram.iris formats/nonogram/cases/five-by-five/input.txt --dzn
width = 5;
height = 5;
% row: array[int] of tuple(array[int] of int)
row = [([1, 1],), ([1, 1],), ([1],), ([1, 1],), ([1, 1],)];
% col: array[int] of tuple(array[int] of int)
col = [([1, 1],), ([1, 1],), ([1],), ([1, 1],), ([1, 1],)];
JSON
iris read formats/nonogram/nonogram.iris formats/nonogram/cases/five-by-five/input.txt --json
{"iris":"0.1","entries":[{"name":"width","type":"int","depth":0,"value":5},{"name":"height","type":"int","depth":0,"value":5},{"name":"row","type":"int","depth":2,"value":[[1,1],[1,1],[1],[1,1],[1,1]]},{"name":"col","type":"int","depth":2,"value":[[1,1],[1,1],[1],[1,1],[1,1]]}]}
Summary
iris read formats/nonogram/nonogram.iris formats/nonogram/cases/five-by-five/input.txt --summary
formats/nonogram/cases/five-by-five/input.txt [nonogram]
  width: int 5
  height: int 5
  row: int array 5 x 1..2
  col: int array 5 x 1..2

Download full case · Open in playground

row-too-wide

A row clue is wider than the board

title "Hand-made invalid clue"
width 5
height 5
rows
6
1,1
1
1,1
1,1
columns
1,1
1,1
1
1,1
1,1

E-CHECK-FAILED

check failed for record 1 of 'row': the clues of a row do not fit into the width of the board

Read rejectedRun from the repository root.
iris read formats/nonogram/nonogram.iris formats/nonogram/cases/row-too-wide/input.txt --dzn
formats/nonogram/cases/row-too-wide/input.txt:5:1: check failed for record 1 of 'row': the clues of a row do not fit into the width of the board
     5 | 6
       | ^
spec: formats/nonogram/nonogram.iris:24

Input rejected

Download full case · Open in playground