import { Sudoku } from "https://esm.town/v/saolsen/sudoku";
type SlotConstraint = {
kind: "slot";
row: number;
col: number;
};
type RowConstraint = {
kind: "row";
row: number;
value: number;
};
type ColConstraint = {
kind: "col";
col: number;
value: number;
};
type BoxConstraint = {
kind: "box";
box: number;
value: number;
};
type Constraint = SlotConstraint | RowConstraint | ColConstraint | BoxConstraint;
const NUM_CONSTRAINTS = 324;
type Slot = {
row: number;
col: number;
value: number;
};
function slotToConstraints(slot: Slot): Constraint[] {
console.assert(slot.row >= 0 && slot.row <= 8);
console.assert(slot.col >= 0 && slot.col <= 8);
console.assert(slot.value >= 1 && slot.value <= 9);
const { row, col, value } = slot;
const box = Math.floor(row / 3) * 3 + Math.floor(col / 3);
return [
{ kind: "slot", row, col },
{ kind: "row", row, value },
{ kind: "col", col, value },
{ kind: "box", box, value },
];
}