From 5ccbb2ef1ca17bcc5e3c2c36158812baa47d10c2 Mon Sep 17 00:00:00 2001 From: Matt Low Date: Thu, 25 Feb 2021 00:49:41 -0700 Subject: [PATCH] Simplified selectColumnSizeHeuristic --- src/sudoku/dlx.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) 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; }