chiark / gitweb /
Group: fix loop bounds in the solver.
authorSimon Tatham <anakin@pobox.com>
Tue, 19 May 2020 20:02:50 +0000 (21:02 +0100)
committerSimon Tatham <anakin@pobox.com>
Wed, 20 May 2020 20:02:04 +0000 (21:02 +0100)
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.

unfinished/group.c

index 60030ba4e03f97e78dc85257ca5ee157787581aa..c27c8f56ea1717070c07238a952ac3d09239bd82 100644 (file)
@@ -312,9 +312,9 @@ static int solver_normal(struct latin_solver *solver, void *vctx)
      * 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] &&