Sudoku Helper

We've taken a step back from the increasing complexity driven by our early experiments in Outpost Thinking. We set the client aside for a moment and ask if we can hack an existing deno server to run executable helpers as if they were CGI scripts. github

We took deno's std/http/server.ts and added the simple logic: if a file to be served is executable, execute it and serve the result. Content type will be inferred from the suffix so we discard usual language conventions and rely on the #! interpreter convention to launch the right engine.

We've used sample applications to drive our work. For this sprint we chose an existing perl script with a colorful history: the sudoku servant. See Sudokant

.

In order to compare implementations we follow the same general structure of the original perl.

Input. We retrieve the current board configuration from the query portion of the url. The 81 board positions are represented by digits when known (givens) and dot when yet to be determined (choices).

Subsets. The rules specify that specific nine element subsets must be filled with digits without duplication. We enumerate the indices of all subsets first by row, then column and square. We can check these in any order so we run them all together.

Rules. We eliminate choices no longer available in a subset based on the board state, the givens from input. We have two versions: at-most-one of every digit and at-least-one of every digit.

for every subset for every index in the subset remove or otherwise mark unavailable choices

Tables. We construct the visual frame for our output as a nested 3x3 square of 3x3 squares, each an "X" that we will soon replace. It is not a coincidence that these markers will appear in the html in the same order as we have numbered the givens and choices.

Choices. We now assemble everything we have learned into html for each place on the board. If the place is a given digit, we show that in a large font. Otherwise we do a little more case analysis to assemble up the desired display.

Output. We finish up by displaying the html version of the board just constructed along with some explanation and credits.

.

We've cast this javascript code into a Deno Deploy service and added a "forced moves" shortcut. github deploy nr1

The New York Times now offers daily sudoku that are reasonably retrieved with a bit of javascript. nyt

[...document.querySelectorAll('.su-cell')] .map(e => e.ariaLabel.replace('empty','.')) .join('')

To be useful this needs to reorder cells to match that of the solver and then call the helper from a bookmarklet.