111 const std::array<std::array<int, V>, V> &starting_mat,
int i,
116 printMat<V>(mat, starting_mat, 9);
122 return solveSudoku<V>(mat, starting_mat, i + 1, 0);
126 if (mat[i][j] != 0) {
127 return solveSudoku<V>(mat, starting_mat, i, j + 1);
131 for (
int no = 1; no <= 9; no++) {
132 if (isPossible<V>(mat, i, j, no, 9)) {
135 bool solution_found = solveSudoku<V>(mat, starting_mat, i, j + 1);
136 if (solution_found) {
156 std::array<std::array<int, V>, V> mat = {
157 std::array<int, V>{5, 3, 0, 0, 7, 0, 0, 0, 0},
158 std::array<int, V>{6, 0, 0, 1, 9, 5, 0, 0, 0},
159 std::array<int, V>{0, 9, 8, 0, 0, 0, 0, 6, 0},
160 std::array<int, V>{8, 0, 0, 0, 6, 0, 0, 0, 3},
161 std::array<int, V>{4, 0, 0, 8, 0, 3, 0, 0, 1},
162 std::array<int, V>{7, 0, 0, 0, 2, 0, 0, 0, 6},
163 std::array<int, V>{0, 6, 0, 0, 0, 0, 2, 8, 0},
164 std::array<int, V>{0, 0, 0, 4, 1, 9, 0, 0, 5},
165 std::array<int, V>{0, 0, 0, 0, 8, 0, 0, 7, 9}};
167 backtracking::sudoku_solver::printMat<V>(mat, mat, 9);
168 std::cout <<
"Solution " << std::endl;
169 std::array<std::array<int, V>, V> starting_mat = mat;
170 backtracking::sudoku_solver::solveSudoku<V>(mat, starting_mat, 0, 0);