{"id":15411947,"url":"https://github.com/fcrozetta/sudokusolver","last_synced_at":"2025-11-08T05:30:37.801Z","repository":{"id":245710763,"uuid":"818954911","full_name":"fcrozetta/SudokuSolver","owner":"fcrozetta","description":"Simple CSP solver algorithm with backtrack","archived":false,"fork":false,"pushed_at":"2024-06-23T15:10:29.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-28T01:40:11.984Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fcrozetta.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-23T11:02:14.000Z","updated_at":"2024-06-23T15:10:33.000Z","dependencies_parsed_at":"2024-06-23T16:39:27.949Z","dependency_job_id":null,"html_url":"https://github.com/fcrozetta/SudokuSolver","commit_stats":null,"previous_names":["fcrozetta/sudokusolver"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fcrozetta%2FSudokuSolver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fcrozetta%2FSudokuSolver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fcrozetta%2FSudokuSolver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fcrozetta%2FSudokuSolver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fcrozetta","download_url":"https://codeload.github.com/fcrozetta/SudokuSolver/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239549995,"owners_count":19657538,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T16:50:40.136Z","updated_at":"2025-11-08T05:30:37.691Z","avatar_url":"https://github.com/fcrozetta.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SudokuSolver\n\nThis is a simple sudoku solver (with bactrack) used for my study on CSP solvers.\n\n\u003c!-- TOC --\u003e\n\n- [SudokuSolver](#sudokusolver)\n  - [Code division](#code-division)\n  - [SudokuGame](#sudokugame)\n  - [\\_reset\\_grid](#_reset_grid)\n  - [input\\_rows](#input_rows)\n  - [SudokuSolver](#sudokusolver-1)\n    - [\\_isPossible](#_ispossible)\n    - [solve](#solve)\n\n\u003c!-- /TOC --\u003e\n\n## Code division\n\nThere are two classes in the [main.py](src/main.py) file:\n- SudokuGame\n- SudokuSolver\n\nWhich are used to manage the game, and solve the game created.\n\n## SudokuGame\n\nThis class contains the base of the sudoku game, but is missing the player controls, and most of the \"game\" itself. In this class we have two functions that we are going to use:\n- _reset_grid\n- input_rows\n\n\n## _reset_grid\n\nThis functions is used to reset the game. It is important to note that \"reset\" means having an empty board.\n\n## input_rows\n\nThis functions will read row by row the sequence of numbers to add to the grid.\nFor this study, no validation was added, and error may occur if a line is updated with invalid inforamtion.\n\n## SudokuSolver\n\nThis class is used to control and solve the sudoku game object. when you instantiate this object, two things are set up. First, the sudoku game is referenced internally (when you modify the game grid in sudoku Solver, you also change it in the object itself). Second, the flag \"hasSolution\" is set to false. This flag is used to return afer the first solution is found.\n\n\u003e The solver assumes the initial grid is not violating any constrains\n\n### _isPossible\n\nThis method is used to validate if the constrains are met. In a more complex CSP solver, this method would have more constrains, and validates if the option to be put under that cell (variable, in domain) is correct.\n\n### solve\n\nThis Method is the main part of the solver. Understanding this part is essential to know how this CSP works.\n\nFirst, we check if the flag hasSolution is true. This means that we found one solution in the solver, and we can return.\n\n\u003e this is also a hint that we are using recursion\n\nthe code then, goes cell by cell (skipping the already filled cells) and try all the options, one by one, using a BFS algorythm. Line 40 shows that we are updating the value, and then going forward by calling the `solve` method again. After that, we check if we found a solution. If not, we backtrack and go to the next possible number. This assumes the game is not broken, and one of the numbers **always** will be possible.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffcrozetta%2Fsudokusolver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffcrozetta%2Fsudokusolver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffcrozetta%2Fsudokusolver/lists"}