simon-git: puzzles (master): Simon Tatham

Commits to Tartarus hosted VCS tartarus-commits at lists.tartarus.org
Wed May 20 21:04:34 BST 2020


TL;DR:
  432590a Group: add a special deduction about the group identity.
  7acc554 Group: fix loop bounds in the solver.

Repository:     https://git.tartarus.org/simon/puzzles.git
On the web:     https://git.tartarus.org/?p=simon/puzzles.git
Branch updated: master
Committer:      Simon Tatham <anakin at pobox.com>
Date:           2020-05-20 21:04:34

commit 432590a05c17b8220efb97ffa038120f1102f5d8
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=432590a05c17b8220efb97ffa038120f1102f5d8;hp=c9b3c3896ca54681d03bd6c25e433affd9809860
Author: Simon Tatham <anakin at pobox.com>
Date:   Tue May 19 21:02:36 2020 +0100

    Group: add a special deduction about the group identity.
    
    In identity-hidden mode, as soon as you find any table entry that
    matches the element indexing its row or column (i.e. a product of
    group elements of the form ab=a or ab=b), then you immediately know
    which element is the group identity, and you can fill in the rest of
    its row and column trivially.
    
    But the Group solver was not actually able to do this deduction.
    Proof: it couldn't solve the game id 4i:1d1d1d1, which is trivial if
    you take this into account. (a^2=a, so a is the identity, and once you
    fill in ax=xa=x for all x, the rest of the grid is forced.)
    
    So I've added dedicated piece of logic to spot the group identity as
    soon as anything in its row and column is filled in. Now that puzzle
    can be solved.
    
    (A thing that I _haven't_ done here is the higher-level deduction of
    determining the identity by elimination. Any table entry that
    _doesn't_ match either its row or column rules out both the row and
    the column from being the group identity - so as soon as you have
    enough table entries to rule out all but one element, you know the
    identity must be the remaining one. At the moment, this is just doing
    the simple version of the deduction where a single table entry tells
    you what _is_ the identity.)
    
    One slightly tricky part is that because this new identity inference
    deduction fills in multiple grid entries at a time, it has to be
    careful to avoid triggering an assertion failure if the puzzle is
    inconsistent - before filling in each entry, it has to make sure the
    value it wants to fill in has not been ruled out by something it
    filled in already. Without that care, an insoluble puzzle can cause
    the solver to crash - and worse, the same can happen on an insoluble
    _branch_ of the guesswork-and-backtracking tree in Unreasonable mode.
    In both cases, the answer is to make sure you detect the problem
    before hitting the assertion, and return -1 for 'inconsistent puzzle'
    if you spot it. Then any guesswork branch that ends up in this
    situation is cleanly abandoned, and we move on to another one.

 unfinished/group.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)

commit 7acc554805a471103bef0a74e4d64fef945dddb9
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=7acc554805a471103bef0a74e4d64fef945dddb9;hp=432590a05c17b8220efb97ffa038120f1102f5d8
Author: Simon Tatham <anakin at pobox.com>
Date:   Tue May 19 21:02:50 2020 +0100

    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(-)



More information about the tartarus-commits mailing list