## ~jleightcap/nonolog

square, monochromatic, nonogram/picross solver in prolog
`README`
`type annotation comments`
`LICENSE`

main
browse  log

### clone

https://git.sr.ht/~jleightcap/nonolog
git@git.sr.ht:~jleightcap/nonolog

You can also use your local clone with git send-email.

## #nonolog

solve nonogram/picross puzzles, that are:

• square: same number of rows are columns (duh)
• monochromatic: only single colored, boolean states
• and nothing fancier

### #usage, examples

start up a prolog repl and load definitions,

```\$ swipl
?- [nono].
true.
```

to solve the example puzzle

``````     11 3
22112
+-----+
2 |     |
2 2 |     |
1 |     |
3 |     |
2 1 |     |
+-----+
``````

`picross/4` takes an array of row restrictions, array of column restrictions, the size, and corresponding matrix.

```?- picross([[2], [2, 2], [1], [3], [2, 1]], [[1, 2], [1, 2], [1], [3, 1], [2]], 5, X).
00011
11011
00010
11100
11010
X = [[0, 0, 0, 1, 1], [1, 1, 0, 1, 1], [0, 0, 0, 1, 0], [1, 1, 1, 0, 0], [1, 1, 0, 1|...]] .
```

this is the expected solution,

``````     11 3
22112
+-----+
2 |   XX|
2 2 |XX XX|
1 |   X |
3 |XXX  |
2 1 |XX X |
+-----+
``````

with under-constrained inputs, this detects all possible solutions, so for a less constrained input:

``````   221
+---+
1 |   |
2 |   |
2 |   |
+---+
``````

two solutions are found;

```?- picross([[1], [2], [2]], [[2], [2], [1]], 3, X).
100
110
011
X = [[1, 0, 0], [1, 1, 0], [0, 1, 1]] ;
001
110
110
X = [[0, 0, 1], [1, 1, 0], [1, 1, 0]] ;
```

corresponding to both valid outputs,

``````   221       221
+---+     +---+
1 |X  |   1 |  X|
2 |XX |   2 |XX |
2 | XX|   2 |XX |
+---+     +---+
``````

and because this is constraint-based prolog, this works in the opposite direction. if we wanted to generate the constraints to generate the puzzle

``````+---+
|XXX|
| X |
|X X|
+---+
``````
```?- picross(X, Y, 3, [[1, 1, 1], [0, 1, 0], [1, 0, 1]]).
111
010
101
X = [[3], [1], [1, 1]],
Y = [[1, 1], [2], [1, 1]] ;
```

which are the constraints;

``````      1 1
121
+---+
3 |XXX|
1 | X |
1 1 |X X|
+---+
``````