From fb28cb4ed2d618c2bcf3a4a0cd2b5a550b245113 Mon Sep 17 00:00:00 2001 From: jleightcap Date: Mon, 21 Jun 2021 06:04:15 -0400 Subject: [PATCH] README --- README.md | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++ nono.prolog | 5 +-- 2 files changed, 126 insertions(+), 4 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..a657544 --- /dev/null +++ b/README.md @@ -0,0 +1,125 @@ +# 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, + +```bash +$ 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. + +```prolog +?- 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; + +```prolog +?- 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| ++---+ +``` + +```prolog +?- 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| + +---+ +``` diff --git a/nono.prolog b/nono.prolog index 3801a4e..8c9de07 100644 --- a/nono.prolog +++ b/nono.prolog @@ -15,8 +15,6 @@ * along with this program. If not, see . */ -% try this out: https://swish.swi-prolog.org/ - :- use_module(library(clpfd)). % just used for transpose/2 % solve a given picross puzzle. @@ -81,8 +79,7 @@ decode(N, E, X) :- % ?- add_encode(1, 1, [1, 2, 3], X). % X = [3, 3]. add_encode(1, 1, [], X) :- X = [2]. -add_encode(0, 0, S, X) :- X = S. -add_encode(0, 1, S, X) :- X = S. +add_encode(0, _, S, X) :- X = S. add_encode(1, 0, S, X) :- X = [1|S]. add_encode(1, 1, S, X) :- X = [A|R], -- 2.45.2