Skip to the content

Kazu数

Generate checked Sudoku and logic puzzles, read native rules and hints, and draw or embed playable boards.

Kazu is the Japanese word 数 for number. About the name

Contents

How-to

Choose Sudoku and number-grid rules

Keep printed codes and variant constraints together.

Choose a native kind

number-place is ordinary Sudoku; jigsaw uses irregular regions, diagonal adds the long diagonals, and sum-cages adds totals in cages. more-or-less is Futoshiki with inequalities; towers is Skyscrapers with edge visibility clues. The kind decides how to decode the givens and which rules the answer must satisfy.

import {KAZU_KINDS,KAZU_SPECS,isKazuSize,generateKazu,checkKazu} from "@johnmorrisdotca/kazu";
console.log(KAZU_KINDS.map(kind=>[kind,KAZU_SPECS[kind].sizes]));
const puzzle = generateKazu("more-or-less",4,"easy",42);
console.log(isKazuSize("more-or-less",4),checkKazu(puzzle.kind,puzzle.size,puzzle.givens,puzzle.solution));
[
  [ 'number-place', [ 4, 6, 9, 16, 25 ] ],
  [ 'jigsaw', [ 5, 6, 7, 9 ] ],
  [ 'diagonal', [ 6, 9 ] ],
  [ 'sum-cages', [ 6, 9 ] ],
  [ 'more-or-less', [ 4, 5, 6, 7 ] ],
  [ 'towers', [ 4, 5, 6, 7 ] ]
]
true { ok: true }

Preserve the complete printed puzzle

A givens code can include regions, cages, inequalities or edge clues after its numeric cells. Do not slice it down to size * size before checking. Use readGivens and the kind-specific decoders; decodeCells alone is only the numeric cell part. layoutOfGivens can be null for the separate inequality/visibility rules.

Seeds are integers from 1 to KAZU_SEED_MOST, and levels easy/medium/hard. Unsupported generation inputs throw. Huge grids or difficult variants can block synchronous host code; use a worker for a responsive custom host. See the established level notes.

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/kazu 2.1.0.