int main(int argc, char **argv) { int option; use_alternate_screen = getenv("VIM") == NULL; setlocale(LC_CTYPE, ""); while ((option = getopt(argc, argv, "dhoq:SvxX")) != -1) { switch (option) { case 'd': descriptions = 1; break; case 'o': /* * Only output description if descriptions are read and * displayed in the list of choices. */ output_description = descriptions; break; case 'q': if ((query = strdup(optarg)) == NULL) err(1, "strdup"); query_size = strlen(query) + 1; break; case 'S': sort = 0; break; case 'v': version(); case 'x': use_alternate_screen = 1; break; case 'X': use_alternate_screen = 0; break; default: usage(); } } argc -= optind; argv += optind; if (query == NULL) { query_size = 64; if ((query = calloc(query_size, sizeof(*query))) == NULL) err(1, "calloc"); } get_choices(); put_choice(selected_choice()); free_choices(); free(query); return EX_OK; }
bool solve_sudoku_wrap(std::vector<std::vector<int>> &M, const std::vector<std::vector<bool>> &given, int N, int i, int j) { if (!given[i][j]) { std::vector<int> choices = get_choices(M, N, i, j); bool res = false; for (int x = 0; x < N && !res; x++) { if (choices[x] != 0) { M[i][j] = choices[x]; // print_sudoku(M, N); // std::cout << std::endl; if ((j == N - 1) && (i < N - 1)) { res = solve_sudoku_wrap(M, given, N, i + 1, 0); } else if (j < N - 1) { res = solve_sudoku_wrap(M, given, N, i, j + 1); } if ((i == N - 1) && (j == N - 1)) { return true; } if (!res) { M[i][j] = 0; } } } return res; } else { if ((j == N - 1) && (i < N - 1)) { return solve_sudoku_wrap(M, given, N, i + 1, 0); } else if (j < N - 1) { return solve_sudoku_wrap(M, given, N, i, j + 1); } if ((i == N - 1) && (j == N - 1)) { return true; } } }