Introduction
A picross, also known as a nonogram, is a logic puzzle in which the player is given an initially blank grid and must shade in particular boxes on the grid to reveal an image. Numbers are written on the top and the left side, and they explain the image's coloration: each number corresponds to an unbroken line of shaded-in boxes in its row or column. Consider any individual row or column from this completed puzzle to see this correspondence:
Not shown in the image is the fact that one can write an "X" to indicate that a box is known not to be shaded in. Partially solving a row or column by shading in and crossing out boxes provides necessary information for the rest of the puzzle, as rows and columns usually cannot be completely solved on their own (for instance, in the image, this is only possible in the first row).
The Challenge
To take the hints for a given row along with the state of each box in the row as inputs, and output the row solved to the fullest extent possible.
Examples
In these examples, let 0
represent a box with an "X", 1
a shaded-in box, and 2
an unknown or unknowable (that is, blank) box.
This row would be input as
[1,3,7,1], [2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2]
and the program should output the following:
[2,2,2,2,2,2,2,2,2,2,2,1,1,2,2,2,2,2,2,2]
This output corresponds to this row, and no more information can be found:
The boxes marked 1
are always that way, no matter the arrangement of the shading. Essentially, if a box always has the same state, it must assume that state, lest the shading contradicts what is known. If there is not a unanimous agreement, then the box is unknowable and is marked 2
.
Input: [1,3,7,1], [2,2,2,2,2,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2]
Output: [2,2,2,2,2,2,0,2,2,2,2,1,1,1,2,2,2,2,2,2]
Input: [6], [2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2]
Output: [0,0,0,0,0,0,0,2,2,2,2,2,1,2,2,2,2,2,0,0,0,0,0,0,0]
If a 6-wide shading were to begin in any of the first 7 boxes, the row would have to have [6,1]
or [7]
as its hints, and so none of the first 7 boxes can be filled in. The same is true for the right side.
Input: [3], [2,0,2,2,2,2,0,2]
Output: [0,0,2,1,1,2,0,0]
Because a 3-wide shading can only fit in the 4-wide gap in the middle, the 1-wide gaps on the edges can be turned into 0
s
Rules
Any three distinct symbols may be used in the place of
0
,1
and2
so long as it is indicated which symbol corresponds to which stateAssume the input hints and row never form an impossible combination
This is code-golf, so the shortest program in bytes in each language wins
0
,1
and2
? For example0112
becomes1000, 0110, 0001
\$\endgroup\$