-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestSudoku.java
102 lines (75 loc) · 2.73 KB
/
TestSudoku.java
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* TestSudoku.java
COPYRIGHT 2006 KRUPCZAK.ORG, LLC.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
For more information, visit:
http://www.krupczak.org/
*/
/**
TestSudoku puzzle solver
@author Bobby Krupczak, rdk@krupczak.org
@version $Id: TestSudoku.java 16 2008-07-21 14:12:38Z rdk $
@see SudokuPuzzle
@see Sudoku
**/
public class TestSudoku {
/* class variables and methods *********************** */
private static void usage(String argv[]) {
System.out.println("Usage: java TestSudoku");
System.exit(-1);
}
public static void main(String argv[])
{
SudokuPuzzle thePuzzle;
thePuzzle = new SudokuPuzzle(9);
System.out.println("TestSudoku starting with size "
+thePuzzle.getSize());
int[][] elements = {
{ 0,5,7,4,9,0,0,0,0 },
{ 9,0,4,2,0,1,3,5,0 },
{ 0,0,6,8,0,5,0,0,9 },
{ 0,6,0,0,0,3,0,7,5 },
{ 5,0,2,7,0,4,8,0,3 },
{ 1,7,0,5,0,0,0,6,0 },
{ 6,0,0,9,0,8,2,0,0 },
{ 0,2,1,3,0,7,6,0,4 },
{ 0,0,0,0,4,2,5,8,0 },
};
int[][] elements1 = {
{ 2,0,0,0,4,6,0,0,3 },
{ 0,0,0,5,7,0,2,4,8 },
{ 4,8,0,0,0,2,5,0,7 },
{ 3,0,7,0,2,8,0,0,4 },
{ 0,1,0,0,0,0,0,2,0 },
{ 6,0,0,4,5,0,7,0,9 },
{ 7,0,1,2,0,0,0,9,5 },
{ 8,3,6,0,9,5,0,0,0 },
{ 9,0,0,7,6,0,0,0,1 },
};
thePuzzle.setElements(elements1);
System.out.println("Going to solve puzzle: ");
thePuzzle.printElements();
if (thePuzzle.solvePuzzle() == true) {
System.out.println("Solution: ");
thePuzzle.printElements();
}
else {
System.out.println("Puzzle is not solvable");
thePuzzle.printElements();
}
}
/* instance variables ******************************** */
/* constructors ************************************* */
/* private methods *********************************** */
/* public methods ************************************ */
} /* class TestSudoku */