From e8f9c2f15db8935ba50c1fbaa2f283cfb4b1456c Mon Sep 17 00:00:00 2001 From: Matt Low Date: Wed, 3 Mar 2021 18:04:28 -0700 Subject: [PATCH] Log the number of dancing link updates --- src/sudoku/math.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/sudoku/math.ts b/src/sudoku/math.ts index a083e74..f84dc99 100644 --- a/src/sudoku/math.ts +++ b/src/sudoku/math.ts @@ -141,7 +141,7 @@ export class SudokuMath { return [...firstRow, ...Array(this.values2 - this.values).fill(0)]; } - generateComplete() { + generateComplete(): [number[], number] { const result = this._baseBoard(); const [header] = this.getDLXHeader(result, true); @@ -157,11 +157,11 @@ export class SudokuMath { const dlx = new DLX(header, callback); dlx.search(); - return result; + return [result, dlx.updates]; } generate(clues: number, attempts = Infinity, totalTime = Infinity) { - const completed = this.generateComplete(); + const [completed, updates] = this.generateComplete(); const [header, dlxRows] = this.getDLXHeader(); // complete header - no candidates removed @@ -183,6 +183,7 @@ export class SudokuMath { const hasOneSolution = () => { solutions = 0; dlx.search(); + updates += dlx.updates; return solutions === 1; }; @@ -248,6 +249,7 @@ export class SudokuMath { removed.forEach((index) => { completed[index] = 0; }); + console.log("DLX updates:", updates); return completed; }