ql-sudoku
v1.0.3
Published
Sudoku solver and generator
Downloads
368
Readme
ql-sudoku
A Sudoku solver and generator library written in TypeScript.
Features
- 🎯 Generate Sudoku puzzles of different sizes (2x2, 3x3, 4x4, 6x6, 9x9)
- 🎮 Multiple difficulty levels (Easy, Medium, Hard)
- 🔍 Solve existing Sudoku puzzles
- 📦 TypeScript support with type definitions
- 🚀 ES modules support
Installation
npm i ql-sudokuUsage
import { generate, solve, SudokuSize, SudokuLevel } from 'ql-sudoku';
// Generate a 9x9 Sudoku puzzle
const sudoku = generate(SudokuSize.NINE, SudokuLevel.MEDIUM);
console.log('Puzzle:');
console.table(sudoku.getBoard());
// Solve the puzzle
const solution = solve(sudoku.getBoard());
if (solution) {
console.log('Solution:');
console.table(solution);
} else {
console.log('No solution found');
}API
generate(size, level)
Generate a Sudoku puzzle with specified size and difficulty.
size:SudokuSize- The grid size (TWO, THREE, FOUR, SIX, NINE)level:SudokuLevel- Difficulty level (EASY, MEDIUM, HARD)- Returns:
Sudokuinstance
solve(board)
Solve a given Sudoku puzzle.
board:number[][]- 2D array representing the Sudoku board- Returns:
number[][] | null- Solution array or null if no solution
SudokuSize
enum SudokuSize {
TWO = '2x2', // 4x4 grid
THREE = '3x3', // 9x9 grid
FOUR = '4x4', // 16x16 grid
SIX = '6x6', // 36x36 grid
NINE = '9x9' // 81x81 grid
}SudokuLevel
enum SudokuLevel {
EASY,
MEDIUM,
HARD
}License
MIT
