-
Notifications
You must be signed in to change notification settings - Fork 2
/
README
75 lines (63 loc) · 2.23 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
SudokuSolver is a C++ library and sample app that can solve any Suduko game
board that can be resolved with standard elimination and deduction logic. This
is code that I originally wrote in 2006 and 2007. I recently rediscovered the
code as a result of inspecting an old hard drive. For this GitHub release, I
cleaned up the code, added modern C++ 11 styles, and made it cross-compile on
both Windows and Unix.
There are some published Suduko puzzles on the Internet that claim to be
"worlds hardest Suduko" or labeled as "hard", but require the solver to use
guess work and backtracking - those are out of scope for this program.
The code is Standard C++ 11 code and should compile most anywhere where your
C++ compiler supports C++ 11. I've tested Windows, Linux, and Mac.
Example. Assume you have an input file that represents the initial state of a
Sudoku board with "." used to indicate an unsolved square. Such a file is
already provided with this source code.
$> cat input.txt
9.63.51..
..5....4.
...9....6
..1.24...
.8.5.3.6.
...16.9..
3....7...
.1....8..
..24.16.3
To compile the code:
$> g++ -std=c++11 cell.cpp sudokuboard.cpp main.cpp -o solver
To compile on Windows, simply start a new Visual Studio project add all the
*.cpp files to the project.
To run the code:
$> ./solver input.txt
And the corresponding output will show the initial state of the board,
and a lot of log statements. The final state of the board is also shown
if the board is solved.
9 ? 6 | 3 ? 5 | 1 ? ?
? ? 5 | ? ? ? | ? 4 ?
? ? ? | 9 ? ? | ? ? 6
---------------------
? ? 1 | ? 2 4 | ? ? ?
? 8 ? | 5 ? 3 | ? 6 ?
? ? ? | 1 6 ? | 9 ? ?
---------------------
3 ? ? | ? ? 7 | ? ? ?
? 1 ? | ? ? ? | 8 ? ?
? ? 2 | 4 ? 1 | 6 ? 3
---------------------
TripleSearch - 2 removed from cell at (r=7 c=5)
TripleSearch - 6 removed from cell at (r=7 c=5)
...
9 4 6 | 3 7 5 | 1 8 2
7 2 5 | 8 1 6 | 3 4 9
1 3 8 | 9 4 2 | 7 5 6
---------------------
6 9 1 | 7 2 4 | 5 3 8
4 8 7 | 5 9 3 | 2 6 1
2 5 3 | 1 6 8 | 9 7 4
---------------------
3 6 9 | 2 8 7 | 4 1 5
5 1 4 | 6 3 9 | 8 2 7
8 7 2 | 4 5 1 | 6 9 3
---------------------
Number of scans - 4
Board has been solved
Board is valid