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.
This commit is contained in:
Simon Tatham
2020-05-19 21:02:50 +01:00
parent 432590a05c
commit 7acc554805

View 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 * So we pick any a,b,c we like; then if we know ab, bc, and
* (ab)c we can fill in a(bc). * (ab)c we can fill in a(bc).
*/ */
for (i = 1; i < w; i++) for (i = 0; i < w; i++)
for (j = 1; j < w; j++) for (j = 0; j < w; j++)
for (k = 1; k < w; k++) { for (k = 0; k < w; k++) {
if (!grid[i*w+j] || !grid[j*w+k]) if (!grid[i*w+j] || !grid[j*w+k])
continue; continue;
if (grid[(grid[i*w+j]-1)*w+k] && if (grid[(grid[i*w+j]-1)*w+k] &&