{"id":15047781,"url":"https://github.com/607011/9piece-solver","last_synced_at":"2025-09-05T17:34:31.012Z","repository":{"id":179083675,"uuid":"640927752","full_name":"607011/9piece-solver","owner":"607011","description":"Solver for Scramble Square™️-like 3×3 puzzles, written in C++","archived":false,"fork":false,"pushed_at":"2023-07-17T09:53:29.000Z","size":1153,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-10T01:08:22.209Z","etag":null,"topics":["cplusplus","cplusplus-11","cpp","educational","educational-project","puzzle-solver","solver"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/607011.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2023-05-15T12:20:30.000Z","updated_at":"2023-08-01T05:14:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"2af33af8-c696-423a-bedd-9854c8b36ab0","html_url":"https://github.com/607011/9piece-solver","commit_stats":null,"previous_names":["607011/9piece-solver"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/607011/9piece-solver","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/607011%2F9piece-solver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/607011%2F9piece-solver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/607011%2F9piece-solver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/607011%2F9piece-solver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/607011","download_url":"https://codeload.github.com/607011/9piece-solver/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/607011%2F9piece-solver/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273790677,"owners_count":25168699,"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","status":"online","status_checked_at":"2025-09-05T02:00:09.113Z","response_time":402,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["cplusplus","cplusplus-11","cpp","educational","educational-project","puzzle-solver","solver"],"created_at":"2024-09-24T21:04:25.692Z","updated_at":"2025-09-05T17:34:30.958Z","avatar_url":"https://github.com/607011.png","language":"C++","readme":"# 9piece-solver\n\n**A Solver for 3x3 puzzles, written in C++**\n\n\n_Copyright ©️ 2023 [Oliver Lau](mailto:ola@ct.de), [Heise](https://www.heise.de/) Medien GmbH \u0026 Co. KG_\n\n---\n\n## Intro\n\nIn puzzles like [Scramble Squares](https://www.scramblesquares.com/) or One Tough Puzzle nine pieces have to be put together to form a 3 by 3 square. Each edge of a piece typically has one of four shapes or images. In case of shapes the positive shape fits the negative like in classical jigsaw puzzles, in case of images each image is split into two halves. Here are two examples:\n\n![Jigsaw sample](doc/sample-pieces.png)\n\n![Scramble Squares Insects sample](doc/scramble-squares-insects.jpg)\n\nAmazingly, there are about 23 billion possible arrangements: 9·8·7·6·5·4·3·2·1 = 9! to permute the positions of all pieces, times 4\u003csup\u003e8\u003c/sup\u003e for all possible orientations. Why not 4\u003csup\u003e9\u003c/sup\u003e? Because rotating the center piece will rotate the whole puzzle.\n\nOne neat algorithm to solve this kind of puzzle is described in the 2001 paper [Using backtracking to solve the Scramble Squares puzzle](doc/backtrackingPaper.pdf) by Keith Brandt et al:\n\n- Place the first piece in the center. Its orientation doesn't matter.\n- Try to place the next piece to the right of the first one, the following ones in a clockwise spiral around the center, like so:\n  ```\n  6 → 7 → 8\n  ↑\n  5   0 → 1\n  ↑       ↓\n  4 ← 3 ← 2\n  ```\n- For every piece test all of the four possible orientations.\n- If it fits the solver goes a level deeper and the process repeats with the remaining pieces until all pieces are placed.\n- If it doesn't fit the next available piece is chosen and the process continues on the same level.\n\nThat's the algorithm this [solver](https://github.com/607011/9piece-solver/blob/main/src/solver.hpp) implements. It will find all solutions to a given puzzle. It's quite efficient: It takes only a couple of hundred tries to find a solution.\n\nA puzzle is described in a file where each line represents one piece and the four integers in the line describe the shape of an edge, e.g.\n\n```\n -4  1  2 -2 \n -4 -4  1  3 \n -1  2  3 -2 \n -3 -1  1  3 \n -4  4  1 -3\n -3  2  3 -1 \n  2 -1 -4  2 \n  4  1 -2 -1 \n  4 -4 -3  3 \n```\n\nTo determine if two edges fit together the algorithm simple adds their values. If their sum is zero, the edges fit, otherwise they don't.\n\nThe output of the solver looks like this for every solution found:\n\n```\n--------------------------\n indexes |     turns      \n---------+----------------\n  1 8 6  |  2/4  1/4  1/4 \n  4 7 3  |  3/4    0  2/4 \n  5 0 2  |  2/4  2/4  2/4 \n--------------------------\n```\n\nThe left column shows the line numbers of the pieces in the original file. The right column shows how many counter-clockwise quarter turns are needed to fit the piece.\n\n\n\n## Prerequisites\n\n- C++11 compiler\n\n\n## Build\n\n\n### Linux, macOS\n\n```\ngit clone https://github.com/607011/9piece-solver.git\ncd 9piece-solver\nmkdir build\ncd build\ncmake -DCMAKE_BUILD_TYPE=Release ..\ncmake --build .\n```\n\n### Windows\n\nIn Visual Studio Developer Console:\n\n```\ngit clone https://github.com/607011/9piece-solver.git\ncd 9piece-solver\nmd build\ncd build\ncmake ..\ncmake --build . --config=Release\n```\n\n\n## Run\n\n```\n9piece-solver data/puzzle-0000.txt\n```\n\n## License\n\nSee [LICENSE](LICENSE).\n\n--- \n\n### Nutzungshinweise\n\nDiese Software wurde zu Lehr- und Demonstrationszwecken geschaffen und ist nicht für den produktiven Einsatz vorgesehen. Heise Medien und der Autor haften daher nicht für Schäden, die aus der Nutzung der Software entstehen, und übernehmen keine Gewähr für ihre Vollständigkeit, Fehlerfreiheit und Eignung für einen bestimmten Zweck.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F607011%2F9piece-solver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F607011%2F9piece-solver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F607011%2F9piece-solver/lists"}