{"id":18396506,"url":"https://github.com/pkkid/python-algorithmx","last_synced_at":"2025-04-07T04:32:43.672Z","repository":{"id":148685628,"uuid":"467726519","full_name":"pkkid/python-algorithmx","owner":"pkkid","description":"AlgorithmX Problems and Solvers","archived":false,"fork":false,"pushed_at":"2025-01-15T23:55:09.000Z","size":52,"stargazers_count":9,"open_issues_count":0,"forks_count":5,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-22T13:23:06.471Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pkkid.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":"2022-03-09T00:49:22.000Z","updated_at":"2025-01-29T13:19:37.000Z","dependencies_parsed_at":"2024-04-29T14:28:25.300Z","dependency_job_id":"0652d888-8240-4d55-a7cc-334bc3f95eca","html_url":"https://github.com/pkkid/python-algorithmx","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/pkkid%2Fpython-algorithmx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkkid%2Fpython-algorithmx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkkid%2Fpython-algorithmx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkkid%2Fpython-algorithmx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pkkid","download_url":"https://codeload.github.com/pkkid/python-algorithmx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247595069,"owners_count":20963939,"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-11-06T02:14:06.019Z","updated_at":"2025-04-07T04:32:43.613Z","avatar_url":"https://github.com/pkkid.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AlgorithmX Problems and Solvers\n\nTrying to efficiently write a program to provide me solutions to [Dragonfjord's\n\"A Puzzle a Day\"](https://www.dragonfjord.com/product/a-puzzle-a-day/) has lead\nme down a slightly mind boggling path of learning what about Donald Knuth's\n[AlgorithmX](https://en.wikipedia.org/wiki/Knuth%27s_Algorithm_X), as well as\n[Exact Cover](https://en.wikipedia.org/wiki/Exact_cover), and\n[Dancing Link](https://en.wikipedia.org/wiki/Dancing_Links)\nalgorithms. I am definitely not an expert in this algorithm, but was able to get\nsomething working with the help of Ali Assaf's post and implementation of AlgorithmX.\n\nThe examples in this repository can solve Sudoku and Pentomino puzzles relativly\nquickly. While all these examples work in Python3, I highly recomend using\n[pypy](https://www.pypy.org/download.html) as it is much faster for these types\nof problems.\n\n## Example Pentomino Solver\n```python\nfrom pentomino import Puzzle\n\nBOARD = \"\"\"\n⬛⬛🟫🟫🟫⬛⬛\n🟫🟫🟫🟫🟫🟫🟫\n🟫🟫🟫🟫🟫🟫🟫\n🟫🟫🟫⬛⬛⬛⬛\n\"\"\"\nPIECES = \"\"\"\n🟪🟪🟪 ⬛🟦⬛ ⬛🟥🟥 🟨🟨⬛ 🟩🟩🟩\n⬛🟪⬛ 🟦🟦🟦 🟥🟥⬛ 🟨🟨⬛ ⬛⬛🟩\n\"\"\"\n\nsolver = Puzzle(BOARD, PIECES, allow_reflections=True)\nsolutions = list(solver.find_solutions())\nfor board in solutions:\n    print(board)\n\n\u003e\u003e\u003e\n⬛⬛🟪🟩🟩⬛⬛\n🟦🟪🟪🟪🟩🟨🟨\n🟦🟦🟥🟥🟩🟨🟨\n🟦🟥🟥⬛⬛⬛⬛\n```\n\n## Example Dragonfjord Command Line Solver\nOnly a single random solution is displayed when running from the command line\nas seeing all solutions was a bit unwieldy.\n```bash\n\u003e python3 puzzle-a-day.py --date=2025-05-29\n🟦🟦🟦🟦⬛🟧⬛\n🟨🟦🟨🟧🟧🟧⬛\n🟨🟨🟨🟧⬜⬜⬜\n🟩🟩🟩⬜⬜🟫🟫\n🟩🟪🟪🟥🟫🟫🟫\n🟩🟪🟪🟥🟥🟥🟥\n⬛🟪🟪⬛⬛⬛⬛\n\nFound 66 solutions after 5.5s.\n```\n\nTo view all available options, run `python3 puzzle-a-day.py --help`. Available\noptions for `--puzzle` are `dragonfjord` and `guanglu`, see `puzzle-a-day.ini`\nfor the puzzle layouts.\n\n## Example Sudoku Solver\nThis solver is not my code, but Ali Assaf's. Copied from his posted example,\ncleaned up Python 3 styles, and commented to help me understand. I included\nit in this repo to hopefully help other's learn this algorithm usage as well.\n\n```python\nfrom sudoku import solve_sudoku\n\ngrid = [\n    [0,1,0, 0,0,0, 0,3,0],\n    [9,0,0, 0,2,0, 1,5,0],\n    [0,0,0, 1,0,0, 0,6,4],\n    [7,0,0, 0,0,0, 0,0,0],\n    [8,0,0, 3,9,0, 5,0,6],\n    [0,0,0, 0,0,0, 0,4,9],\n    [5,0,0, 0,7,1, 0,0,0],\n    [0,0,8, 0,0,0, 0,9,1],\n    [0,4,0, 2,6,0, 0,0,5]]\nfor solution in solve_sudoku(grid):\n    print(*solution, sep='\\n')\n    print()\n\n\u003e\u003e\u003e\n[4, 1, 2, 7, 5, 6, 9, 3, 8]\n[9, 8, 6, 4, 2, 3, 1, 5, 7]\n[3, 5, 7, 1, 8, 9, 2, 6, 4]\n[7, 9, 1, 6, 4, 5, 8, 2, 3]\n[8, 2, 4, 3, 9, 7, 5, 1, 6]\n[6, 3, 5, 8, 1, 2, 7, 4, 9]\n[5, 6, 3, 9, 7, 1, 4, 8, 2]\n[2, 7, 8, 5, 3, 4, 6, 9, 1]\n[1, 4, 9, 2, 6, 8, 3, 7, 5]\n```\n\n\n## Thanks To\n* [Donald Knuth](https://en.wikipedia.org/wiki/Donald_Knuth) for coming up with\n  [AlgorithmX](https://en.wikipedia.org/wiki/Knuth%27s_Algorithm_X).\n* [Ali Assaf](https://www.cs.mcgill.ca/~aassaf9/index.html) for the short implementation\n  of AlgorithX as well as a [great write up and example](https://www.cs.mcgill.ca/~aassaf9/python/algorithm_x.html).\n\n## License\nGNU General Public License \u003chttp://www.gnu.org/licenses/\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpkkid%2Fpython-algorithmx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpkkid%2Fpython-algorithmx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpkkid%2Fpython-algorithmx/lists"}