From 7acc554805a471103bef0a74e4d64fef945dddb9 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Tue, 19 May 2020 21:02:50 +0100 Subject: [PATCH] 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. --- unfinished/group.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/unfinished/group.c b/unfinished/group.c index 60030ba..c27c8f5 100644 --- a/unfinished/group.c +++ b/unfinished/group.c @@ -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] &&