jassl
v1.0.14
Published
Just Another Sudoku Solving Library
Downloads
28
Maintainers
Readme
JASSL
(WIP) Just Another Sudoku Solving Library
About
JASSL aims to be a sudoku solving companion library. In the simplest use-case it functions as a mere puzzle validator and cell tracker but has capabilities to completely solve most sudoku puzzles
Install
npm install --save jassl
API Overview
Create a new puzzle instance
// import library
let SudokuPuzzle = require('jassl');
// empty list of values for the puzzle
let puzzleValues = Array(81).fill();
// create sudoku instance: defaults to 9x9 with 9 3x3 sectors
let sudoku = new SudokuPuzzle(puzzleValues);
Create puzzle instance with non-traditional sector size
// empty list of values for the puzzle
let puzzleValues = Array(10 * 10).fill();
// creates a 10x10 with 10 5x2 sectors
let sudoku = new SudokuPuzzle(puzzleValues, {sectorWidth: 5, sectorHeight: 2});
Attempt to solve puzzle
// returns true if the puzzle was fully solved
let solved = sudoku.solve();
External Solve attempt
try {
sudoku.cells[0].solveTo(1);
// invalid solution for cell
} catch (e) {
console.error(e.message);
}
Retrieving applicable candidates
// for a cell
let cellCandidates = sudoku.cells[0].candidates;
// For a row
let rowCandidates = sudoku.rows[0].candidates;
// For a column
let columnCandidates = sudoku.columns[0].candidates;
// For a sector
let sectorCandidates = sudoku.sector[0].candidates;