shithub: puzzles

Download patch

ref: 7acc554805a471103bef0a74e4d64fef945dddb9
parent: 432590a05c17b8220efb97ffa038120f1102f5d8
author: Simon Tatham <anakin@pobox.com>
date: Tue May 19 17:02:50 EDT 2020

Group: fix loop bounds in the solver.

Applications of the associativity rule were iterating over only n-1 of
the group elements, because I started the loops at 1 rather than 0. So
the solver was a bit underpowered, and would have had trouble with
some perfectly good unambiguous game ids such as 6i:2a5i4a6a1s .

(The latin.c system is very confusing for this, because for historical
reasons due to its ancestry in Solo, grid coordinates run from 0 to
n-1 inclusive, but grid _contents_ run from 1 to n, using 0 as the
'unknown' value. So there's a constant risk of getting confused as to
which kind of value you're dealing with.)

This solver weakness only affects puzzles in 'identity hidden' mode,
because in normal mode, the omitted row and column are those of the
group identity, and applications of associativity involving the
identity never generate anything interesting.

--- a/unfinished/group.c
+++ b/unfinished/group.c
@@ -312,9 +312,9 @@
      * So we pick any a,b,c we like; then if we know ab, bc, and
      * (ab)c we can fill in a(bc).
      */
-    for (i = 1; i < w; i++)
-	for (j = 1; j < w; j++)
-	    for (k = 1; k < w; k++) {
+    for (i = 0; i < w; i++)
+	for (j = 0; j < w; j++)
+	    for (k = 0; k < w; k++) {
 		if (!grid[i*w+j] || !grid[j*w+k])
 		    continue;
 		if (grid[(grid[i*w+j]-1)*w+k] &&