




Break My Sudoku Checker
Thead Owner : Ashamed1644926390,
Category : Everything Coding,
0 Comment,
58 Read
Viewers:
1 Guest(s)
03-21-2014, 02:48 PM
Your Task
Create a 9x9 2D array that is detected as a good table by my code, but is actually a bad table.
My Code
More readable code: http://pastebin.com/1UWNhdYs
Create a 9x9 2D array that is detected as a good table by my code, but is actually a bad table.
My Code
Code:
public class Board
{
private int [][] boardBits;
public Board(int [][] setup) {
boardBits = setup;
}
public String checkBoard() {
int sum = 0;
if (noBadSpots()) {
for (int i = 0; i < 9; i++) {
for (int a = 0; a < 9; a++)
sum += boardBits[i][a];
if (sum != 45)
return "Invalid Table";
sum = 0;
}
sum = 0;
for (int i = 0; i < 9; i++) {
for (int a = 0; a < 9; a++)
sum += boardBits[a][i];
if (sum != 45)
return "Invalid Table";
sum = 0;
}
sum = 0;
for (int xbase = 0; xbase <= 6; xbase += 3) {
for (int ybase = 0; ybase <= 6; ybase += 3) {
for (int i = xbase; i <= xbase + 2; i++) {
for (int a = ybase; a <= ybase + 2; a++)
sum += boardBits[i][a];
}
if (sum != 45)
return "Invalid Table";
sum = 0;
}
}
return "Good Table";
} else {
return "Invalid Table";
}
}
private boolean noBadSpots()
{
for (int a = 0; a < 9; a++) {
if (boardBits[a][0] == boardBits[a][2])
return false;
for (int b = 0; b < 9; b++)
if (boardBits[a][b] < 1 || boardBits[a][b] > 9)
return false;
}
return true;
}
}
More readable code: http://pastebin.com/1UWNhdYs