sudoku_hui.ijs

Contributor: Roger Hui
Updated: 2022 7 14
Depend: nil
Definitions: loaded to locale base
Status: dev - entering a new puzzle
Script source: sudoku_hui.ijs

The sudoku solver taken from J Software Wiki as provided by Roger Hui.
Roger Hui’s sudoku solver
View the source script to see how Roger solved the problem using J.
Roger’s notes from Wiki
Create and solve a new puzzle
In a Jqt session open script sudoku_hui.ijs
Edit the noun NEW_PZ
Execute to create NEW_PZ
Check the puzzle: see NEW_PZ
Solve the puzzle: sudokuz NEW_PZ
Note
Develop GUI front end
Develop JHS

Definitions

B BLK
N NEW_PZ
P PZ_1, PZ_1A, PZ_2, PZ_3, PZ_4, PZ_5, PZ_6, PZ_7
S sudoku, sudoku_c, sudokuz

BLK n -
sudokuz m Sudoku solver

NEW_PZ (noun)

Create a new puzzle
Edit the noun NEW_PZ
Excute to create NEW_PZ
see NEW_PZ
sudokuz NEW_PZ

PZ_1 (noun)

Puzzle 1: 1 solution
  sudokuz PZ_1

PZ_1A (noun)

Same as PZ_1 with different data format
 sudokuz PZ_1A

PZ_2 (noun)

Puzzle 2: 6 Solutions
 sudokuz PZ_2

PZ_3 (noun)

Puzzle 3: 106 Solutions
 sudokuz PZ_3

PZ_4 (noun)

Puzzle 4: Blank Puzzle: To many Solutions - HANGS
 sudoku PZ_$

PZ_5 (noun)

Puzzle 5: 0 Solutions: Bad puzzle: First Row doubling of 2
 sudokuz PZ_5

PZ_6 (noun)

Puzzle 1: 1 solution
  sudokuz PZ_6

PZ_7 (noun)

Puzzle 1: 1 solution
  sudokuz PZ_7

sudoku (monad)

Form: explicit
Depend: guess,ok,assign
Solves puzzle as table of solutions (N,81)
N = number of solutions

Syntax

  sudoku(PZ)
PZ = sudoku puzzle

Example

  sudoku PZ_1
2 8 3 6 7 1 9 4 5 9 7 6 5 4 8 2 ...
  sudoku PZ_2
1 8 3 6 7 2 9 4 5 4 7 6 5 9 8 2 ...
2 8 3 6 7 1 9 4 5 4 7 6 5 9 8 2 ...
2 8 3 6 7 1 9 4 5 4 7 6 5 9 8 2 ...
2 8 3 6 7 1 9 4 5 4 7 6 5 9 8 2 ...
2 8 3 6 7 1 9 4 5 4 7 6 5 9 8 2 ...
2 8 3 6 7 1 9 4 5 9 7 6 5 4 8 2 ...
 Show tables run:
  see PZ_1, sudoku PZ_1
┌─────────────┬─────────────┐
│┌───┬───┬───┐│┌───┬───┬───┐│
││2..│67.│...│││283│671│945││
││..6│...│2.1│││976│548│231││
││4..│...│8..│││415│392│876││
│├───┼───┼───┤│├───┼───┼───┤│
││5..│..9│3..│││567│419│382││
││.3.│...│.5.│││834│267│159││
││..2│8..│..7│││192│835│467││
│├───┼───┼───┤│├───┼───┼───┤│
││..1│...│..4│││321│786│594││
││7.8│...│6..│││758│924│613││
││...│.53│..8│││649│153│728││
│└───┴───┴───┘│└───┴───┴───┘│
└─────────────┴─────────────┘
  see PZ_2, sudoku PZ_2
  see PZ_3, sudoku PZ_3

sudoku_c (monad)

Form: explicit
Depend: sudoku
Counts the number of solutions

Syntax

sudoku_c(PZ)
PZ = sudoku puzzle

Example

  sudoku_c PZ_1
1
  sudoku_c PZ_2
6
  sudoku_c PZ_3
106