aboutsummaryrefslogtreecommitdiff
path: root/unfinished
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2020-05-23 08:41:43 +0100
committerSimon Tatham <anakin@pobox.com>2020-05-23 09:08:08 +0100
commit31cb5227e6df543a077910d0f3e7c7e169e7c01e (patch)
tree0e2a7b230b582e0a28120858cb7dc1185aa4895d /unfinished
parentf21d3e4c74b23380f397a7ee0416928ee971a15d (diff)
downloadpuzzles-31cb5227e6df543a077910d0f3e7c7e169e7c01e.zip
puzzles-31cb5227e6df543a077910d0f3e7c7e169e7c01e.tar.gz
puzzles-31cb5227e6df543a077910d0f3e7c7e169e7c01e.tar.bz2
puzzles-31cb5227e6df543a077910d0f3e7c7e169e7c01e.tar.xz
Group: fill in the latin.c validator function.
This actually fixes the example game id mentioned in the previous commit. Now 12i:m12b9a1zd9i6d10c3y2l11q4r is reported as Unreasonable rather than ambiguous, on the basis that although the solver still recurses and finds two filled grids, the validator throws out the nonsense one at the last minute, leaving only one that's actually legal.
Diffstat (limited to 'unfinished')
-rw-r--r--unfinished/group.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/unfinished/group.c b/unfinished/group.c
index 3a44a67..c7dcb2c 100644
--- a/unfinished/group.c
+++ b/unfinished/group.c
@@ -450,7 +450,37 @@ static usersolver_t const group_solvers[] = { DIFFLIST(SOLVER) };
static bool group_valid(struct latin_solver *solver, void *ctx)
{
- return true; /* FIXME */
+ int w = solver->o;
+#ifdef STANDALONE_SOLVER
+ char **names = solver->names;
+#endif
+ int i, j, k;
+
+ for (i = 0; i < w; i++)
+ for (j = 0; j < w; j++)
+ for (k = 0; k < w; k++) {
+ int ij = grid(i, j) - 1;
+ int jk = grid(j, k) - 1;
+ int ij_k = grid(ij, k) - 1;
+ int i_jk = grid(i, jk) - 1;
+ if (ij_k != i_jk) {
+#ifdef STANDALONE_SOLVER
+ if (solver_show_working) {
+ printf("%*sfailure of associativity: "
+ "(%s%s)%s = %s%s = %s but "
+ "%s(%s%s) = %s%s = %s\n",
+ solver_recurse_depth*4, "",
+ names[i], names[j], names[k],
+ names[ij], names[k], names[ij_k],
+ names[i], names[j], names[k],
+ names[i], names[jk], names[i_jk]);
+ }
+#endif
+ return false;
+ }
+ }
+
+ return true;
}
static int solver(const game_params *params, digit *grid, int maxdiff)