Compare commits

..

1 Commits

Author SHA1 Message Date
e8f9c2f15d Log the number of dancing link updates 2021-03-03 18:17:41 -07:00

View File

@ -141,7 +141,7 @@ export class SudokuMath {
return [...firstRow, ...Array(this.values2 - this.values).fill(0)]; return [...firstRow, ...Array(this.values2 - this.values).fill(0)];
} }
generateComplete() { generateComplete(): [number[], number] {
const result = this._baseBoard(); const result = this._baseBoard();
const [header] = this.getDLXHeader(result, true); const [header] = this.getDLXHeader(result, true);
@ -157,16 +157,15 @@ export class SudokuMath {
const dlx = new DLX(header, callback); const dlx = new DLX(header, callback);
dlx.search(); dlx.search();
return result; return [result, dlx.updates];
} }
generate(clues: number, attempts = Infinity, totalTime = Infinity) { 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 const [header, dlxRows] = this.getDLXHeader(); // complete header - no candidates removed
let solutions = 0; let solutions = 0;
let updates = 0;
const dlx = new DLX(header, () => ++solutions >= 2); const dlx = new DLX(header, () => ++solutions >= 2);
const candidates: DNode[][] = Array.from(Array(this.values2), () => const candidates: DNode[][] = Array.from(Array(this.values2), () =>