feat: expand sudoku analysis and interoperability

This commit is contained in:
2026-08-30 23:21:56 +02:00
parent 4a9869baa0
commit 8ca9300ab3
73 changed files with 12482 additions and 384 deletions
+16
View File
@@ -111,6 +111,13 @@ export function solveExact(
"timeoutMs",
);
const compiled = compilePuzzle(normalized);
const preferredSolution =
normalized.solution !== undefined &&
board.every(
(value, cell) => value === 0 || value === normalized.solution?.[cell],
)
? normalized.solution
: undefined;
const random: RandomSource | undefined =
options.seed === undefined ? undefined : seededRandom(options.seed);
const solutions: number[][] = [];
@@ -157,6 +164,15 @@ export function solveExact(
const chosen = selection[0];
let choices = selection[1];
if (random !== undefined) choices = shuffled(choices, random);
else {
const preferred = preferredSolution?.[chosen];
if (preferred !== undefined && choices.includes(preferred)) {
choices = [
preferred,
...choices.filter((value) => value !== preferred),
];
}
}
for (const value of choices) {
board[chosen] = value;
search();