Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

indow Help Sudoku.pdfx 1 1 3 (+) 100% Sudoku is a popular puzzle game. The goal

ID: 3732258 • Letter: I

Question

indow Help Sudoku.pdfx 1 1 3 (+) 100% Sudoku is a popular puzzle game. The goal of Sudoku is to fill a 9-9 grid with numbers so that each row, column and 3x3 section contain all of the digits between I and 9. (This means that if a number is used twice in the same row, column or 3x3 section, some number will be missing.) You can play Sudoku and learn about the game here http://www sudoku.com/ or here http://www.websudoku.com Here is a partially played Sudoku game, all initial moves are correct. See if you can continue playing the game until all the empty spaces are filled

Explanation / Answer

public static boolean checkRow(int[][] sudoku, int row ) {
BitSet bsRow = new BitSet(9);
for (int j = 0; j < 9; j++) {
if (sudoku[row][j] == 0) continue;
if (bsRow.get(sudoku[row][j] - 1))
return false;
else {
bsRow.set(board[row][j] - 1);
}
}
return true;
}

public static boolean CheckColumn(int[][] sudoku, int col) {
BitSet bsColumn = new BitSet(9);
for (int j = 0; j < 9; j++) {
if (board[j][col] == 0) continue;
if (bsColumn.get(board[j][col] - 1))
return false;
else {
bsColumn.set(board[j][col] - 1);
}
}
return true;
}

public static boolean CheckGrid(int[][] sudoku, int row, int col) {
BitSet threeByThree = new BitSet(9);
for (int i = row; i < row + 3; i++) {
for (int j = col; j < col + 3; j++) {
if (board[i][j] == 0) continue;
if (threeByThree.get(board[i][j] - 1))
return false;
else
threeByThree.set(board[i][j] - 1);
}
}  
return true;
}

Below 3 functions written in Java.