Sudoku: Difference between revisions
Content added Content deleted
Line 1,910: | Line 1,910: | ||
}</lang> |
}</lang> |
||
Usage |
Usage |
||
<lang csharp> |
<lang csharp>using System.Linq; |
||
using static System.Linq.Enumerable; |
|||
using static System.Console; |
using static System.Console; |
||
using System.IO; |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
//https://staffhome.ecm.uwa.edu.au/~00013890/sudoku17 format |
|||
var puzzle = "000028000800010000000000700000600403200004000100700000030400500000000010060000000"; |
|||
⚫ | |||
⚫ | |||
var num = int.Parse(args[0]); |
|||
var puzzles = File.ReadLines(@"sudoku17.txt").Take(num); |
|||
⚫ | |||
var single = puzzles.First(); |
|||
⚫ | |||
var watch = new System.Diagnostics.Stopwatch(); |
|||
watch.Start(); |
|||
⚫ | |||
watch.Stop(); |
|||
WriteLine($"{single}: {watch.ElapsedMilliseconds} ms"); |
|||
WriteLine($"Doing {num} puzzles"); |
|||
var total = 0.0; |
|||
watch.Start(); |
|||
foreach (var puzzle in puzzles) { |
|||
watch.Reset(); |
|||
watch.Start(); |
|||
SudokuFastMemoBFS.Run(puzzle); |
|||
watch.Stop(); |
|||
total += watch.ElapsedMilliseconds; |
|||
Write("."); |
|||
} |
|||
watch.Stop(); |
|||
WriteLine($"\nPuzzles:{num}, Total:{total} ms, Average:{total / num:0.00} ms"); |
|||
ReadKey(); |
|||
⚫ | |||
⚫ | |||
}</lang> |
}</lang> |
||
Output |
Output |
||
<pre> |
<pre> |
||
693784512 |
|||
617328945 |
|||
487512936 |
|||
894517236 |
|||
125963874 |
|||
325946781 |
|||
932651487 |
|||
978651423 |
|||
568247391 |
|||
256834179 |
|||
741398625 |
|||
143792658 |
|||
319475268 |
|||
731489562 |
|||
856129743 |
|||
489265317 |
|||
274836159 |
|||
562173894 |
|||
000000010400000000020000000000050407008000300001090000300400200050100000000806000: 165 ms |
|||
</pre> |
|||
Doing 100 puzzles |
|||
.................................................................................................... |
|||
Puzzles:100, Total:6131 ms, Average:61.31 ms</pre> |
|||
===“Automatic” Solution=== |
===“Automatic” Solution=== |