Anonymous user
Sudoku: Difference between revisions
m
→Best First Search "Smart" Backtrack Solution
Line 1,837:
internal readonly record struct Square (int Row, int Col);
internal record Constraints (IEnumerable<int> ConstrainedRange, Square Square);
internal class Cache : Dictionary<Square,
internal record CacheGrid (int[][] Grid, Cache Cache);
Line 1,846:
private static int RowCol(int rc) => rc <= 2 ? 0 : rc <= 5 ? 3 : 6;
private static bool Solve(this CacheGrid cg,
foreach (var i in
if (cg.Cache.Count == finished || cg.
cg.Grid[row][col] = 0;▼
}
return false;
}
Line 1,877 ⟶ 1,874:
range.Where(val => grid.Valid(row, col, val));
private static
cg.Cache.ContainsKey(square)
? cg.Cache[square]
: cg.Cache[square]=cg.Grid.SortedCells();
private static
(from row in domain
from col in domain
where grid[row][col] == 0
let cell = new Constraints(grid.Constraints(row, col), new Square(row, col))
private static CacheGrid Parse(string input) =>
Line 1,947 ⟶ 1,943:
}</lang>
Output
<pre>693784512
487512936
125963874
Line 1,957 ⟶ 1,952:
856129743
274836159
000000010400000000020000000000050407008000300001090000300400200050100000000806000:
Doing 100 puzzles
....................................................................................................
Puzzles:100, Total:
===“Automatic” Solution===
|