So far I have a 2D int array the reads in a file and initializes/creates the sudoku board in the array.
I am struggling with a method that solves the puzzle. In order to 'help' solve the puzzle, I have a 3D array which uses index 0 to hold the number of candidates left for each cell. The array is initialized to set this to 9 for all empty cells for now. Once a candidate has been eliminated, it decrements the number in index 0. I also have a variable K, which is the number to test (1-9). If K is a candidate, the 3D array is set to 1 for each number K that is a candidate.
The issue I am stuck on is testing the row, column and box for K to see if it's a candidate of the cell while solving. How do I search the row for the number I'm testing? This might be an easy solve!
Here is my sudo-code, I'm not sure if my logic is wrong or what because I can't seem to convert it to code. I'd really appreciate any help!
for(row 1 -> 9) {
for(col 1 -> 9) {
if(index 0 in 3D array != 1
&& index K in 3D array != 1) {
is K in the row?
if yes, set P[row][col][k] = 0
decrement P[row][col][0]
if K is not in the row, test the column
repeat above
if K is not in the column, test the box
repeat above

New Topic/Question
Reply




MultiQuote








|