Hello Everyone. I am making a sudoku solver for an assignment, and I ran into a problem of my 2D Integer array not updating.
The input consists of a 9x9 puzzle with 0s for the missing values. I read this input and then place it into the 2D array. during this process I also count the number of 0s. After I create a 1D Integer array with the length being the number of 0s. I then proceed to link the 0s in the 2D array to one of the elements in the 1D array, which I initialize to 1. I then call a recursion which changed the 1D array using a brute force recursion to generate all the possible solutions. When I print the 1D array yout it changes like it is supposed to, but when I print out the 2D array it still has all the 0s filled in with 1s and doesn't change. What could be causing this problem?
Thanks for the help.
here is the portion of the code that links the elements
Integer[][] ans;
Integer[] pS;
int zeroCount = 0;
ans = new Integer[9][9];
for (int i = 0; i < 9; i++){
for (int j = 0; j < 9; j++){
ans[j][i] = new Integer(in.readInt());
System.out.print( ans[j][i] + " ");
if (ans[j][i] == 0)
zeroCount++;
}
System.out.println();
}
System.out.println("Num 0s = " + zeroCount);
pS = new Integer[zeroCount];
for (int i = 0; i < pS.length; i++){
pS[i] = new Integer(i + 1);
}
int ansCount = 0;
System.out.println("linking answer array to the solution");
for (int i = 0; i < 9; i++){
for (int j = 0; j < 9; j++){
if (ans[j][i] == 0){
System.out.println("linking (" + j + ", " + i + ") and " + ansCount);
//pS[i] = new Integer(1);
ans[j][i] = pS[ansCount];
ansCount ++;
}
}
}