for (int j = 0; j < 9; j++) { for (int k = 0; k <9; k++) { tempArr[k] = sudoku[k
ID: 3616417 • Letter: F
Question
for (int j = 0; j < 9; j++) {for (int k = 0; k <9; k++) {
tempArr[k] = sudoku[k][j];
}
}
Here is my code so far and I don't know if this is possible but Ihave a 9x9 grid of ints and I want to check each 3x3 like in asudoku puzzle. The way I'm checking is put those 9 values into anarray and comparing them but I am stuck on how to make a double forloop to check each 3x3 grid either go horizontally or verticallyjust as long as I'm checking each 3x3 grid once. Thanks.
Explanation / Answer
// checkrows for(int r= 0; r < 9; r++) { for(int c = 0; c< 9; c++) { tempArr[c] = sudoku[r][c]; //check contents of tempArr here } } // check cols for(int c= 0; c < 9; c++) { for(int r = 0; r< 9; r++) { tempArr[r] = sudoku[r][c]; //check contents of tempArr here } } // check 3x3 grids for(int i= 0; i < 3; i++) { for(int j = 0; j< 3; j++) { int loc = 0; for(int r= 0; r < 3; r++) { for(int c= 0; c < 3; c++) { tempArr[loc++] = sudoku[r+i*3][c+j*3]; // check contents oftempArr here } } } }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.