Menu

#4 Steppable solver

open
nobody
None
5
2007-12-19
2007-12-19
No

It would be great if there were some interface at the module level to run a single step and get an explanation of what to do next and why:

>>> sudoku.step()
{ algorithm: locked_sets, indices: (vertical, (3,), (1, 7)), values: (1, 2), positions: (1, 7), execute: <function> }

This would do the same thing as solve, but as soon as it would be able to reduce the possibilities on one cell, it would instead return the algorithm, loop indices, and values, together with some kind of callback (or key to an "apply" function, or whatever) that could be used to execute the reduction. (Maybe a generator would be a better design?)

That particular result means that the only values in R3C1 and R3C7 are 1 and 2, and therefore those values can be removed from all other cells in R3. (Obviously this would only be a hit if there were any other cells in R3 containing either 1 or 2.)

This means that pysdk would have to represent, store, load, and print "penciled" cells.

This feature could be used almost trivially to log the steps to a solution (like the answers at brainbashers, except those aren't auto-generated):

def logsolution(self):
while True:
nextstep = self.step()
if not nextstep:
if self.finished():
return
raise Unsolvable
self.log(nextstep)
nextstep.execute()

A GUI hint function is another obvious use. For example, color the 1 and 2 in R3C1 and R3C7 green, and all other 1s and 2s in R3 red, and change the "auto" button to remove all the red ones instead of its usual function of doing all dup removals (see below).

Or a CLI hinter that just logs and applies one step and saves the result:

% pysdk.py -t su1.sdk su2.sdk
Solving one step... locked set 18 in column 1, rows 5, 6

Being able to pass an algorithm or list of algorithms to either step or solve would also be handy. For example, you could verify that a puzzle is solvable without using algorithms that you find annoying. Or solve((duplicate_removal, pinned_square)) (or pysdk -tDP maybe?) to turn 182 trivial steps into one big one, leaving you ready for the next interesting challenge. Or just implement brainbashers' "Auto pencil marks" button.

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.