diff --git a/src/sudoku/dlx.ts b/src/sudoku/dlx.ts index 1eb9f49..dd076e2 100644 --- a/src/sudoku/dlx.ts +++ b/src/sudoku/dlx.ts @@ -33,18 +33,13 @@ type SolutionCallback = (output: DNode[]) => boolean; type ColumnSelector = (header: CNode) => CNode; function selectColumnSizeHeuristic(header: CNode): CNode { - let minSize = Infinity; - let minColumn: CNode | undefined; - let curColumn = header; + let minColumn = header.right; + let curColumn = minColumn; while ((curColumn = curColumn.right) !== header) { - if (curColumn.column.size < minSize) { - minSize = curColumn.column.size; + if (curColumn.size < minColumn.size) { minColumn = curColumn; } } - if (!minColumn) { - throw new Error("minColumn is undefined, this shouldn't be possible."); - } return minColumn; }