int main(int argc, char *argv[]) { // Welcome the user to the program cout << "\n\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl; cout << "Welcome to Jon's Sudoku solver." << endl; cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n" << endl; // If the user passed the puzzle file as an argument, run with it. if (argv[1]) { // Call Puzzle constructor passing it the name of the file Puzzle sudoku( argv[1] ); // Now go through the print and solve steps/commands printAndSolve( sudoku ); // Else if the didn't pass the program a puzzle to solve, ask them for // a puzzle filename } else { string filename; cout << "No puzzle file was passed to the program as an argument." << endl; cout << "Please enter the filename of the puzzle you wish to solve." << endl; cout << ">> "; cin >> filename; // Call Puzzle constructor passing it the name of the file Puzzle sudoku( filename ); // Now go through the print and solve steps/commands printAndSolve( sudoku ); } return 0; }
int main(int argc, char **argv) { char **grid; if (error_check(argc, argv)) { print_error(); return (0); } grid = set_grid_parameters(argv); if (grid == NULL) print_error(); sudoku(grid); if (grid[9] == ERROR) print_error(); else { grid[9] = UNIQUE; if (sudoku(grid) && check_solution(grid)) print_grid(grid); else print_error(); } free(grid); return (0); }
int next(int ar[][n*n],int row,int col) { int x; if(col<=(n*n-2)) {x=sudoku(ar,row,col+1);return x;} else if(row<=(n*n-2)) {x=sudoku(ar,row+1,0);return x;} else return 1; }
int main() { std::vector< std::vector<int> > data = { {0,0,0, 0,0,0, 0,1,2}, {0,0,0, 0,3,5, 0,0,0}, {0,0,0, 6,0,0, 0,7,0}, {7,0,0, 0,0,0, 3,0,0}, {0,0,0, 4,0,0, 8,0,0}, {1,0,0, 0,0,0, 0,0,0}, {0,0,0, 1,2,0, 0,0,0}, {0,8,0, 0,0,0, 0,4,0}, {0,5,0, 0,0,0, 6,0,0}, }; if(sudoku(data)) { printout_sudoku(data); } else { std::cout << "Failed to find a solution" << std::endl; } return 0; }
int main(int argc, char **argv) { char **sudo_tb; int index; int index_malloc; index_malloc = 0; if (argc == 10 && is_valid_number(argv) == 1) { index = 0; sudo_tb = (char**)malloc(9 * sizeof(char*)); while (index_malloc < 9) { sudo_tb[index_malloc] = (char*)malloc(10 * sizeof(char)); index_malloc++; } copy_sudo(argv, sudo_tb); if (is_valid_char(argv) == 1 && sudoku(sudo_tb, 0)) print_sudoku(sudo_tb); else write(1, "Erreur\n", 7); free_grid(sudo_tb); } else write(1, "Errer\n", 7); return (0); }
int main() { FILE *ifp; ifp = fopen("sudoku.txt", "r"); if (ifp == NULL) { printf("Couldn't open sudoku.txt input file!\n"); return 0; } int sud[81] = {0}; int index = 0; fscanf(ifp, "%d", &sud[index]); while(!feof(ifp)) { index++; if (index > 81) { printf("sudoku.txt contains more than 81 digits! Sudoku is invalid.\n"); return 0; } fscanf(ifp, "%d", &sud[index]); } if (index < 81) { printf("sudoku.txt contains less than 81 digits! Sudoku is invalid.\n"); return 0; } fclose(ifp); sudoku(sud); printSudoku(sud); return 0; }
int sudoku(char **puzzle) { int row; int col; char num; if (!find_dot_pos(puzzle, &row, &col)) { return (1); } num = '1'; while (num <= '9') { if (possible_find(puzzle, row, col, num)) { puzzle[row][col] = num; if (sudoku(puzzle)) { return (1); } puzzle[row][col] = '.'; } num++; } return (0); }
int main() { int i,j; printf("Enter the order of the puzzle\n"); scanf("%d",&n); int length=n*n; int ar[length][length],a[length]; printf("Enter the puzzle\n"); for(i=0;i<n*n;i++) { for(j=0;j<n*n;j++) { scanf("%d",&ar[i][j]); } } for(i=0;i<n*n;i++) {a[i]=i+1;} int c=sudoku(ar,0,0); if(c==0) printf("\nThe sudoku is not solvable"); for(i=0;i<n*n;i++) { for(j=0;j<n*n;j++) { printf(" %d ",ar[i][j]); } printf("\n"); } }
int main (int argc, char *argv[]) { int code; TParams tp = {.mat1.add = NULL,.mat2.add = NULL }; if ((code = processParams (&tp, argc, argv)) != RET_OK) { errmsg (code); return EXIT_FAILURE; }; switch (tp.function) { case 0: errmsg (RET_OK); break; case 1: code = sucet (&(tp.mat1), &(tp.mat2)); break; case 2: code = sucin (&(tp.mat1), &(tp.mat2)); break; case 3: code = submatrix (&(tp.mat1), &(tp.mat2)); break; case 4: code = crot (&(tp.mat1)); break; case 5: code = plough (&(tp.mat1)); break; case 6: code = sudoku (&(tp.mat1)); break; default: return EXIT_FAILURE; } if (tp.mat1.add != NULL) { freeMat (&(tp.mat1)); } if (tp.mat2.add != NULL) { freeMat (&(tp.mat2)); } if (code != RET_OK) { errmsg (code); return EXIT_FAILURE; } return EXIT_SUCCESS; }
int main() { /* matriz que guarda o tabuleiro */ int tabuleiro[9][9] = {{0}}; if (sudoku(tabuleiro)) imprime(tabuleiro); else printf("Sem solucao\n"); return 0; }
int main(int argc, char **argv) { try { clock_t begin_time, summary_time = clock(); begin_time = clock(); Photo sudoku("9.jpg"); std::cout << "Open image: " << double(clock() - begin_time) / CLOCKS_PER_SEC << " sec." << std::endl; // 1) Resize begin_time = clock(); sudoku.resize(512, 512); std::cout << "Resizing: " << double(clock() - begin_time) / CLOCKS_PER_SEC << " sec." << std::endl; // 2) Binarization begin_time = clock(); Filter::AdaptiveBinarization(sudoku, 4, 0.04); std::cout << "Adaptive Binarization: " << double(clock() - begin_time) / CLOCKS_PER_SEC << " sec." << std::endl; GridRecognition recognition(sudoku); // 3) Rotate begin_time = clock(); double angle = recognition.getHorizontalAngle(); std::cout << "getHorizontalAngle: " << double(clock() - begin_time) / CLOCKS_PER_SEC << " sec." << std::endl; sudoku.rotate(angle); std::cout << "getHorizontalAngle + Rotation: " << double(clock() - begin_time) / CLOCKS_PER_SEC << " sec." << std::endl; // 4) Crop begin_time = clock(); Rectangle grid = recognition.getGridCoords(); std::cout << "getGridCoords: " << double(clock() - begin_time) / CLOCKS_PER_SEC << " sec." << std::endl; sudoku.crop(grid.x, grid.y, grid.width, grid.height); std::cout << "getGridCoords + crop: " << double(clock() - begin_time) / CLOCKS_PER_SEC << " sec." << std::endl; // 5) Split digits begin_time = clock(); vector< Point > points = recognition.getLinesCrossPoints(); std::cout << "getLinesCrossPoints: " << double(clock() - begin_time) / CLOCKS_PER_SEC << " sec." << std::endl; recognition.splitOnDigits(points, "digits"); std::cout << "getLinesCrossPoints + splitOnDigits: " << double(clock() - begin_time) / CLOCKS_PER_SEC << " sec." << std::endl; sudoku.save("test.jpg"); std::cout << "Summary: " << double(clock() - summary_time) / CLOCKS_PER_SEC << " sec." << std::endl; } catch(Magick::Exception &error_) { std::cout << "Caught exception: " << error_.what() << std::endl; system("pause"); return 1; } system("pause"); return 0; }
void Sudoku::process(std::istream& input, std::ostream& output) { std::vector<std::string> lines; std::copy(std::istream_iterator<std::string>(input), std::istream_iterator<std::string>(), std::back_inserter(lines)); int count = 0; int total = lines.size(); for (auto& line: lines) { Sudoku sudoku(line); sudoku.solve(); output << sudoku; count++; progress_bar(count, total); } std::cout << std::endl; }
int main(int argc, char *argv[]) { // Do not set processor affinity here. It prevents threads from // running on multiple cores. // Actually, a data pointer and a pointer to a function are not convertible. // This depends on x64 ABI specific behavior. static_assert(sizeof(uintptr_t) == sizeof(&PrintPattern), "Unexpected uintptr_t size"); static_assert(sizeof(sudokuXmmPrintFunc) == sizeof(uintptr_t), "Unexpected sudokuXmmPrintFunc size"); sudokuXmmPrintFunc = reinterpret_cast<uintptr_t>(&PrintPattern); if (!SudokuLoader::CanLaunch(argc, argv)) { std::cout << "Cannot solve sudoku maps, counting only\n"; return 1; } SudokuLoader sudoku(argc, argv, &std::cin, &std::cout); return sudoku.Exec(); }
bool sudoku(std::vector< std::vector<int> >& data) { int x, y; if(!find_free_position(data, x, y))//the sudoku is fully filled now return true; else { //get all free positions and iterate for(int i = 1; i <= 9; i++) { if(no_violation(data, x, y, i)) { data[x][y]=i; if(sudoku(data)) return true; data[x][y] = 0; } } return false;//all possibility fails } }
t_bool sudoku(char **grid) { int row; int col; char num; if (grid[9] == ERROR) return (TRUE); if (!find_empty_square(grid, &row, &col)) return (is_unique_solution(grid)); num = '1'; while (num <= '9') { if (valid_guess(grid, row, col, num)) { grid[row][col] = num; if (sudoku(grid)) return (TRUE); grid[row][col] = EMPTY; } num++; } return (FALSE); }