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

Reference · Number-puzzle engines

KazuHinttype

A HINT: the next cell a person could fill in by looking, and why.

It reasons from what is right on the grid so far (the printed numbers and every entry that agrees with the answer; a wrong entry is treated as empty, so a hint never builds on a mistake) the way a person does, one step at a time:

  1. a cell that only one number fits (only-number): every other number is already in its row, column, box, region, diagonal or cage, or a cage's sum, a Futoshiki mark or a Skyscrapers clue rules it out (by says which, when one did);
  2. a number that fits only one cell of a group (only-place): the row, column, box, region, diagonal or cage it must go in, and where.

When neither is left (a hard puzzle asks for a guess here) it says so (answer): the tightest cell, whose number is the answer's, with no reason a single step gives. Null when every cell is already right.

Import it

import type { KazuHint } from "@johnmorrisdotca/kazu";

Definition

type KazuHint = {
    cell: number;
    value: number;
    why: "only-number" | "only-place" | "answer";
    group?: {
        type: "row" | "column" | "box" | "region" | "diagonal";
        index: number;
    };
    by?: "cage" | "marks" | "clues";
    replaces: boolean;
};

Members

NameTypeDescription
cellnumber
valuenumber
why"only-number" | "only-place" | "answer"
group (optional){ type: "row" | "column" | "box" | "region" | "diagonal"; index: number; } | undefined

only-place: the group the number has one place in.

by (optional)"marks" | "cage" | "clues" | undefined

only-number: what ruled the others out beyond the groups, if anything did.

replacesboolean

Whether the cell holds a wrong number now, which this one replaces.

Examples

import type { KazuHint, KazuPuzzle } from "@johnmorrisdotca/kazu";
import { decodeCells, readGivens } from "@johnmorrisdotca/kazu";

const puzzle: KazuPuzzle = {"kind":"number-place","size":4,"level":"easy","seed":42,"givens":"14..2..1412.3..4","solution":"1432234141233214"};
const kind = puzzle.kind;
const size = puzzle.size;
const givens = puzzle.givens;
const answer = puzzle.solution;
const printed = readGivens(kind,size,givens)!;
const cells = printed.cells;
const solution = decodeCells(answer,size)!;
const blank = cells.findIndex(value=>value===0);
const value: KazuHint = {cell:blank,value:solution[blank],why:"answer",replaces:false};
console.log(value);
{ cell: 2, value: 3, why: 'answer', replaces: false }

What it prints (run when this page was built)

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