Sudoku: Difference between revisions
Content added Content deleted
m (→Constraint Satisfaction (Norvig): 3.7 ms looked too good, even if could not find issue but this 6.7 ms timings with updated code I trust better) |
|||
Line 4,253: | Line 4,253: | ||
/// Using depth-first search and propagation, try all possible values. |
/// Using depth-first search and propagation, try all possible values. |
||
let rec search (values:Map<_,_>)= |
let rec search (values:Map<_,_>)= |
||
let rec some = function |
|||
| [] -> None // No Solution |
|||
| s::sx -> |
|||
values[s] |
|||
⚫ | |||
|> function |
|||
| Some seqx when Seq.isEmpty seqx -> some sx // reduces calls to find fewest possibilities |
|||
| Some seq -> Some seq // returns Some in previous stack's tryPick |
|||
| _ -> None // returns None in previous stack's tryPick |
|||
// Choose the unfilled square s with the fewest possibilities |
|||
[for s in squares do if Seq.length values[s] > 1 then Seq.length values[s] ,s] |
[for s in squares do if Seq.length values[s] > 1 then Seq.length values[s] ,s] |
||
|> function |
|> function |
||
| [] -> Some values // Solved! |
| [] -> Some values // Solved! |
||
| list -> |
| list -> // tryPick ~ Norvig's `some` |
||
⚫ | |||
// Core API |
// Core API |
||
Line 4,387: | Line 4,378: | ||
5 9 8 |7 3 6 |2 4 1 |
5 9 8 |7 3 6 |2 4 1 |
||
Elapsed milliseconds = |
Elapsed milliseconds = 15 ms |
||
All puzzles in sudoku17 |
All puzzles in sudoku17 |
||
Puzzles:49151, Total: |
Puzzles:49151, Total:327.15 s, Average:6.66 ms</pre> |
||
===SLPsolve=== |
===SLPsolve=== |