{"id":20188650,"url":"https://github.com/der3318/sudoku-generator","last_synced_at":"2026-05-31T01:31:18.849Z","repository":{"id":92549097,"uuid":"297064540","full_name":"der3318/sudoku-generator","owner":"der3318","description":"Python Scripts - Sudoku Puzzle Random Generation","archived":false,"fork":false,"pushed_at":"2020-10-10T09:19:38.000Z","size":6,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-13T18:33:35.994Z","etag":null,"topics":["generator","sudoku"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/der3318.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2020-09-20T11:48:26.000Z","updated_at":"2023-06-12T20:03:01.000Z","dependencies_parsed_at":"2023-06-26T02:32:39.503Z","dependency_job_id":null,"html_url":"https://github.com/der3318/sudoku-generator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/der3318%2Fsudoku-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/der3318%2Fsudoku-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/der3318%2Fsudoku-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/der3318%2Fsudoku-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/der3318","download_url":"https://codeload.github.com/der3318/sudoku-generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241622604,"owners_count":19992504,"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":["generator","sudoku"],"created_at":"2024-11-14T03:30:03.669Z","updated_at":"2025-12-01T06:05:27.625Z","avatar_url":"https://github.com/der3318.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## #️⃣ Sudoku Generator\n\n![python](https://img.shields.io/badge/python-3+-blue.svg)\n![dependency](https://img.shields.io/badge/dependency-none-green.svg)\n![etc](https://img.shields.io/badge/etc-few%20seconds-yellow.svg)\n![license](https://img.shields.io/badge/license-none-blueviolet.svg)\n\nRandomly generate a sudoku game and output its solution as well. It is guaranteed that there is EXACTLY ONE possible solution.\n\n\n### 📔 Usage\n\nClone or download the scripts from the repository. Import the modules and that's all:\n\n```python\n# example.py\n\nfrom sudoku import Sudoku, SudokuCell, SudokuCellValue\nfrom generator import SudokuGenerator\n\ngenerator = SudokuGenerator(maxEmptyCells = 50)\n(game, solution) = generator.generate()\n\nprint(game)\nprint(solution)\n```\n\n![Imgur](https://i.imgur.com/LurZnAE.png)\n\n\n### 📝 Interfaces\n\n[sudoku.py](https://github.com/der3318/sudoku-generator/blob/master/sudoku.py) contains all the basic interfaces.\n\n| Class | Attribute | Description |\n| :- | :- | :- |\n| SudokuCellValue | Enum | digits of a cell including SudokuCellValue.EMPTY, DIGIT1, etc. |\n| SudokuCell | row/col/block | returns a integer from 0 to 8 to describe the position of the cell |\n| SudokuCell | val | returns the corresponding SudokuCellValue of the cell |\n| Sudoku | numberOfRows/numberOfCols | should be integer 9 |\n| Sudoku | getCell(row, col) | returns the reference to the cell at the position or raises an exception |\n| Sudoku | setCell(cell) | updates the Sudoku game using this SudokuCell |\n\nBoth game and solution are an instances of Sudoku. Here is a short example:\n\n```python\ncell = game.getCell(8, 0)                 # get the cell at the bottom left corner from generated game\nprint(cell.block)                         # should be 6\nprint(cell.val == SudokuCellValue.EMPTY)  # should be TRUE\n\ncell = solution.getCell(8, 0)             # get the cell at the bottom left corner from its solution\nprint(cell.val == SudokuCellValue.DIGIT6) # should be TRUE\n```\n\n\n### 🔑 Implementation\n\nThe idea is pretty simple without any fancy algorithm. First of all, what we need is a quick (best hypothesis based BFS) and powerful [sudoku solver](https://github.com/der3318/sudoku-generator/blob/master/solver.py) having the ability to:\n\n| Property | Description |\n| :- | :- |\n| SudokuSolver.__trySolve(sudoku) | tries to solve the game randomly |\n| SudokuSolver.doesSolutionExist | indicates whether it can find a solution |\n| SudokuSolver.isSolutionUnique | indicates whether the solution is unique |\n\nThen, we initialize the game with an empty borad in [sudoku generator](https://github.com/der3318/sudoku-generator/blob/master/generator.py) and solve it using the above solver. This is the solution we are going to return.\n\nThe last thing required is to iteratively pop a random cell from the solution. In each round, the poped result should be tested and make sure it still has only one solution. Otherwise, the cell is considered kept.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fder3318%2Fsudoku-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fder3318%2Fsudoku-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fder3318%2Fsudoku-generator/lists"}