{"id":16237954,"url":"https://github.com/codegoalie/sudoku-solver","last_synced_at":"2025-04-08T08:48:52.026Z","repository":{"id":66782772,"uuid":"43685686","full_name":"codegoalie/sudoku-solver","owner":"codegoalie","description":"A sudoku solver in go","archived":false,"fork":false,"pushed_at":"2016-01-28T23:53:38.000Z","size":28,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-14T05:43:48.206Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","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/codegoalie.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}},"created_at":"2015-10-05T13:25:22.000Z","updated_at":"2016-01-12T02:48:03.000Z","dependencies_parsed_at":"2023-05-20T07:15:49.423Z","dependency_job_id":null,"html_url":"https://github.com/codegoalie/sudoku-solver","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/codegoalie%2Fsudoku-solver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codegoalie%2Fsudoku-solver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codegoalie%2Fsudoku-solver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codegoalie%2Fsudoku-solver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codegoalie","download_url":"https://codeload.github.com/codegoalie/sudoku-solver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247809375,"owners_count":20999806,"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-10T13:38:05.174Z","updated_at":"2025-04-08T08:48:52.010Z","avatar_url":"https://github.com/codegoalie.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sudoku Solver\n\n[ ![Codeship Status for chrismar035/sudoku-solver](https://codeship.com/projects/91a82d50-a3b1-0133-d1b4-3641d785a31d/status?branch=master)](https://codeship.com/projects/129313)\n\nThis generates and solved Sudoku puzzles with the goal to \"discover\" all \npossible puzzles and solutions. Sudoke Solver employes different algorithms\nto generate and solve puzzles as described below.\n\n## Solvers\n\nSudoku Solver has two classes of solvers: single and multi-solvers. Single\nsolvers will find a single solution for a puzzle while multi-solvers will\nfind multiple solutions for a single problem. The strategy of the mult-solver\nwill determine if it can find all solutions to a puzzle or not.\n\n## Single Solvers\n\n### Backtracking\n\nThis is the most naive and simplest solver. It will try every possible \ncombination of values for unknown squares in order until a solution is found.\nThis solver is also the default solver.\n\n```\nsolver := solver.NewSolver()\nsolution := solver.Solve(grid)\n\n// or\nsolver := solver.NewBacktrackingSolver()\nsolution := solver.Solve(grid)\n```\n\n### Logical\n\nThe logical solver attempts to use only logic rules and cancellation to solve\npuzzles. In its current state, it can only solve very easy puzzles.\n\n```\nsolver := solver.NewLogicalSolver()\nsolution := solver.Solve(grid)\n```\n\n### Random backtracking\n\nThe random backtracking solver is similar to the backtracking solver except that\nit will try values for each unknown square in random (not numerical) order. The\ndigits 1-9 are shuffled for each square before the solver begins and as the\nsolver progresses that order of digits is used.\n\n```\nsolver := solver.NewRandBacktrackingSolver()\nsolution := solver.Solve(grid)\n```\n\n## Multi-solvers\n\n### Backtracking\n\nThe multi-backtracking solver uses the same underlying algorithm as the single\nbacktracking solver except that it does not stop at the first solution. Instead,\nit continues and finally returns a slice of solutions.\n\n```\nsolver := solver.NewMultiBacktrackingSolver()\nsolutions := solver.Solve(grid)\n```\n\n## CLI Usage\n\nCurrenly, there is a very naive solver implemented. It can solve \"easy\" level\npuzzles. To exercise it on the command line, run or build `cli/main.go`. It will\nread puzzles from a `puzzles.txt` in the same directory. `puzzles.txt` should\nhave puzzles separated by a new line and consist of 81 consecutive digits with 0\nrepresenting blanks and 1-9 representing given squares. For example, a\n`puzzles.txt` containing two puzzles (one that we can solve and one we can't):\n\n```\n010006527780145009000020010005000746000907000671000900030090000900483065168500090\n750000020100200000300090406000170000001030500000048000809050002000007003060000051\n```\n\nThe cli program will nicely print out the puzzle and then the solution (or as\nmuch as could be solved) followed by true or false whether the puzzle was fully\nsolved. For example, the `puzzles.txt` above would produce the following output:\n\n```\nPuzzle\n_1_ __6 527\n78_ 145 __9\n___ _2_ _1_\n\n__5 ___ 746\n___ 9_7 ___\n671 ___ 9__\n\n_3_ _9_ ___\n9__ 483 _65\n168 5__ _9_\n\nSolution\n419 836 527\n782 145 639\n356 729 418\n\n295 318 746\n843 967 251\n671 254 983\n\n534 691 872\n927 483 165\n168 572 394\ntrue\nPuzzle\n75_ ___ _2_\n1__ 2__ ___\n3__ _9_ 4_6\n\n___ 17_ ___\n__1 _3_ 5__\n___ _48 ___\n\n8_9 _5_ __2\n___ __7 __3\n_6_ ___ _51\n\nSolution\n75_ ___ _2_\n1__ 2__ ___\n3__ _9_ 4_6\n\n___ 17_ ___\n__1 _3_ 5__\n___ _48 ___\n\n8_9 _5_ __2\n___ __7 __3\n_6_ ___ _51\nfalse\n```\n\n## Data format\n\nPuzzles and solutions are represented as 81 element integer arrays. With each\nelement, corresponding to a cell in the puzzle grid; left to right, top to\nbottom.\n\n```\n 0  1  2   3  4  5   6  7  8\n 9 10 11  12 13 14  15 16 17\n18 19 20  21 22 23  24 25 26\n\n27 28 29  30 31 32  33 34 35\n36 37 38  39 40 41  42 43 44\n45 46 47  48 49 50  51 52 53\n\n54 55 56  57 58 59  60 61 62\n63 64 65  66 67 68  69 70 71\n72 73 74  75 76 77  78 79 80\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodegoalie%2Fsudoku-solver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodegoalie%2Fsudoku-solver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodegoalie%2Fsudoku-solver/lists"}