Trying to test validity of a sudoku puzzle: Having trouble with checking for duplicates in each 3x3 square -
here's method:
public static boolean hasduplicatesinsections(int[][] puzzle){ z = 2; w = 0; while(z <= 8){ for(i = w; <= z; i++){ for(j = w; j <= z; j++){ for(l = w; l <= z; l++){ for(k = w; k <= z; k++){ if ((puzzle[l][k] == puzzle[i][j]) && (puzzle[l][k] != 0) && (k != j)){ system.out.println("there match in square. shame on you."); homecoming true; } } } } } z += 3; w += 3; } system.out.println("there wasn't match in square. job!"); homecoming false; } i made 9x9 2-d int array puzzle. 0 means there's blank space. method looks through each 3x3 square , says whether duplicates found in one. still says there wasn't match when there was. can see might wrong?
found wrong. of comparisons , iterations right except when checked:
(k != j)) it checking if column wasn't equal column wrong. did add together indexes of rows , columns , compare them so:
(l+k) != (i+j)) which worked perfectly!
duplicates sudoku
No comments:
Post a Comment