// Sudoku Verifier // // This test question was inspired by the Sudoku Solver // program written by Aaron Logan and Austin Lyons // who took this class in Spring 2006. // This solution uses a modified version of their code. // // Check out: http://www.cs.iastate.edu/~alex/classes/2006_Spring_207/examples_lectures/chap11/Sudoku_Solver.java public class Program4_v1 { public static void main(String[] args) { /* Sample Solution to a Sudoku Puzzle */ int[][] S= {{1,9,3, 2,8,7, 6,4,5}, {7,2,6, 4,9,5, 8,3,1}, {8,5,4, 1,3,6, 7,9,2}, {3,8,2, 5,7,9, 4,1,6}, {4,7,9, 8,6,1, 2,5,3}, {6,1,5, 3,4,2, 9,7,8}, {9,3,8, 6,5,4, 1,2,7}, {5,4,1, 7,2,8, 3,6,9}, {2,6,7, 9,1,3, 5,8,4}}; // Test the rows for(int row=0; row< 9; row++) for(int col=0; col<9; col++) { for(int k=0; k< 9; k++) if((col != k) && (S[row][col] == S[row][k])) System.out.println("Problem detected on row " + (row+1)); } // Test the columns for(int col=0; col<9; col++) for(int row=0; row< 9; row++) { for(int k=0; k< 9; k++) if((row != k) && (S[row][col] == S[k][col])) System.out.println("Problem detected on column " + (row+1)); } // Test the 3x3 squares for(int row=0; row<9; row++) for(int col=0; col< 9; col++) { for(int i=0; i<3; i++) for(int j=0; j<3; j++) { int testRow = 3*(row/3)+i; int testCol = 3*(col/3)+j; if((row != testRow) && (col != testCol) && (S[row][col] == S[testRow][testCol])) System.out.println("Problem detected in square " + (row/3 +1) + "x" + (col/3+1)); } } } }