-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmgwright_Sudoku.java
199 lines (177 loc) · 3.83 KB
/
mgwright_Sudoku.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// Name : Matthew Wright
// Class : 1400-005
// Program # : 7
// Due Date : Friday, February 27th, 2009 @ 11:59 PM
//
// Honor Pledge : On my honor as a student of the University
// of Nebraska at Omaha, I have neither given nor received
// unauthorized help on this homework assignment.
//
// NAME: Matthew Wright
// NUID: 832
// EMAIL: [email protected]
// Partners: NONE
// Description: This program takes 4 columns and 4 rows of numbers and evaluates them to see if they are valid Sodoku groupings.
import java.util.Scanner;
public class mgwright_Sudoku
{
public static void main( String args[] )
{
//Output game instructions
System.out.print("Welcome to the Sudoku Checker v1.0!\n\nThis program checks simple, small, 4x4 Sudoku grids for correctness. Each column, row and 2x2 region contains the numbers 1 through 4 only once.\n\nTo check your Sudoku, enter your board one row at a time, with each digit separated by a space. Hit ENTER at the end of a row.\n\n");
Scanner in = new Scanner(System.in);
int num1a, num2a, num3a, num4a, num1b, num2b, num3b, num4b, num1c, num2c, num3c, num4c, num1d, num2d, num3d, num4d;
int valid = 1;
//Accept input and load variables
System.out.print("Enter Row 1: ");
num1a = in.nextInt();
num1b = in.nextInt();
num1c = in.nextInt();
num1d = in.nextInt();
System.out.print("Enter Row 2: ");
num2a = in.nextInt();
num2b = in.nextInt();
num2c = in.nextInt();
num2d = in.nextInt();
System.out.print("Enter Row 3: ");
num3a = in.nextInt();
num3b = in.nextInt();
num3c = in.nextInt();
num3d = in.nextInt();
System.out.print("Enter Row 4: ");
num4a = in.nextInt();
num4b = in.nextInt();
num4c = in.nextInt();
num4d = in.nextInt();
//Check Regions, Rows and Columns
//REGION 1
if(num1a + num1b + num2a + num2b == 10)
{
System.out.println("\nREG-1:GOOD");
}
else
{
valid = 0;
System.out.println("\nREG-1:BAD");
}
//REGION 2
if(num3a + num4a + num3b + num4b == 10)
{
System.out.println("REG-2:GOOD");
}
else
{
valid = 0;
System.out.println("REG-2:BAD");
}
//REGION 3
if(num1c + num1d + num2c + num2d == 10)
{
System.out.println("REG-3:GOOD");
}
else
{
valid = 0;
System.out.println("REG-3:BAD");
}
//REGION 4
if(num3c + num3d + num4c + num4d == 10)
{
System.out.println("REG-4:GOOD");
}
else
{
valid = 0;
System.out.println("REG-4:BAD");
}
//ROW 1
if(num1a + num1b + num1c + num1d == 10)
{
System.out.println("ROW-1:GOOD");
}
else
{
System.out.println("ROW-1:BAD");
valid = 0;
}
//ROW 2
if(num2a + num2b + num2c + num2d == 10)
{
System.out.println("ROW-2:GOOD");
}
else
{
System.out.println("ROW-2:BAD");
valid = 0;
}
//ROW 3
if(num3a + num3b + num3c + num3d == 10)
{
System.out.println("ROW-3:GOOD");
}
else
{
System.out.println("ROW-3:BAD");
valid = 0;
}
//ROW 4
if(num4a + num4b + num4c + num4d == 10)
{
System.out.println("ROW-4:GOOD");
}
else
{
System.out.println("ROW-4:BAD");
valid = 0;
}
//COLUMN 1
if(num1a + num2a + num3a + num4a == 10)
{
System.out.println("COL-1:GOOD");
}
else
{
System.out.println("COL-1:BAD");
valid = 0;
}
//COLUMN 2
if(num1b + num2b + num3b + num4b == 10)
{
System.out.println("COL-2:GOOD");
}
else
{
System.out.println("COL-2:BAD");
valid = 0;
}
//COLUMN 3
if(num1c + num2c + num3c + num4c == 10)
{
System.out.println("COL-3:GOOD");
}
else
{
System.out.println("COL-3:BAD");
valid = 0;
}
//COLUMN 4
if(num1d + num2d + num3d + num4d == 10)
{
System.out.println("COL-4:GOOD");
}
else
{
System.out.println("COL-4:BAD");
valid = 0;
}
//Output validity
if(valid == 1)
{
System.out.println("\nSUDO:VALID");
}
else
{
System.out.println("\nSUDO:INVALID");
}
}
}