UNPKG

createsudokupuzzle

Version:
45 lines (44 loc) 2.01 kB
/** * Finds the first empty cell in a Sudoku grid. * @param grid - The Sudoku grid. * @returns The row and column indices of the first empty cell, or an empty array if no empty cells are found. */ export declare function findFirstEmpty(grid: Array<Array<number>>): [number, number] | []; /** * Finds all empty cells in a Sudoku grid. * @param grid - The Sudoku grid. * @returns The row and column indices of all empty cells, or an empty array if no empty cells are found. */ export declare function findAllEmpty(grid: Array<Array<number>>): [number, number][]; /** * Checks if placing a number in a cell is valid according to Sudoku rules. * @param grid - The Sudoku grid. * @param row - The row index. * @param col - The column index. * @param num - The number to place. * @param outputReason - Whether to output the reason for invalid placement. * @returns If outputReason is undefined or false, it'll return boolean, else an object with `valid` indicating if the placement is valid and `reason` providing the reason if invalid. */ export declare function validatePlacement(grid: Array<Array<number>>, row: number, col: number, num: number, outputReason?: boolean): { valid: boolean; reason?: string; } | boolean; /** * Validates a Sudoku grid. * @param puzzle - The Sudoku grid. * @param allowZero - Whether zeros are allowed in the grid, usually applicable to checking if a move is legal. * @returns True if valid, false otherwise. */ export declare function validate(puzzle: Array<Array<number>>, allowZero?: boolean): boolean; /** * Generates a Sudoku puzzle with a specified number of blank cells. * @param blank - The number of blank cells. * @returns The generated Sudoku grid. */ export declare function generate(blank?: number): Array<Array<number>>; /** * Solves a Sudoku puzzle. * @param puzzle - The Sudoku grid. * @returns The solved grid or throws an error if unsolvable. */ export declare function solve(puzzle: Array<Array<number>>): Array<Array<number>>;