{"id":20801629,"url":"https://github.com/gijs-pennings/kenken-solver","last_synced_at":"2025-07-29T02:07:51.563Z","repository":{"id":164371234,"uuid":"330391319","full_name":"gijs-pennings/kenken-solver","owner":"gijs-pennings","description":"Fast backtracking solver for KenKen puzzles","archived":false,"fork":false,"pushed_at":"2021-12-03T23:50:43.000Z","size":44,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-12T02:46:26.468Z","etag":null,"topics":["backtracking","kenken","puzzle","solver"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gijs-pennings.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2021-01-17T12:58:04.000Z","updated_at":"2025-02-03T01:44:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"3e81bce9-711e-416d-9835-115e319bbe52","html_url":"https://github.com/gijs-pennings/kenken-solver","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gijs-pennings/kenken-solver","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gijs-pennings%2Fkenken-solver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gijs-pennings%2Fkenken-solver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gijs-pennings%2Fkenken-solver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gijs-pennings%2Fkenken-solver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gijs-pennings","download_url":"https://codeload.github.com/gijs-pennings/kenken-solver/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gijs-pennings%2Fkenken-solver/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267617643,"owners_count":24116208,"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-07-29T02:00:12.549Z","response_time":2574,"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":["backtracking","kenken","puzzle","solver"],"created_at":"2024-11-17T18:19:26.913Z","updated_at":"2025-07-29T02:07:51.539Z","avatar_url":"https://github.com/gijs-pennings.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# KenKen solver\n\nThis is a (somewhat optimized) backtracking solver in C++11 for [KenKen](https://en.wikipedia.org/wiki/KenKen) puzzles, also known as Calcudoku. It is licensed under the [ISC license](LICENSE.txt).\n\nThe puzzle input is read from a file (path given as argument) and its solution is printed to `stdout`. No validity or uniqueness checks are performed. The format is easily determined from the available [examples](examples), noting that cages with the subtraction or division operator *must* be of size 2.\n\nTiming information is printed to `stderr`. Only the time spent backtracking is measured; I/O is ignored, for example. On my high-end machine from 2014, the running time ranges from [\u003c1μs](examples/kenkenpuzzle-expert-S.ken) to [~2.2s](examples/menneske9-4474.ken). 'Average' puzzles (6x6) are solved in [≪1ms](examples/menneske6-74285.ken).\n\n\n## Some implementation details\n\n* Each cage stores its intermediate result (`current`), i.e. the result of the calculation involving all non-empty cells. This way, new values can be tested more efficiently, without querying other cage cells.\n* Each column, row, and cage keeps a list of candidates, i.e. values that are not proven to be illegal. This list is stored as a bitset (a simple `int` suffices) where the `i`th bit is set if `i` is a possible value. This makes it possible to take intersections and find the 'next' candidate in O(1) time, using the `\u0026` operator and `__builtin_ctz` intrinsic (count trailing zeros) respectively.\n* Using [candidates.py](candidates.py), bitsets for all cage configurations of size ≤5 are precomputed (larger cages are rare and therefore not worth the additional space). Here, a grid size of 9 and the 'worst' cage shape (i.e. a staircase, which permits the most duplicates) is assumed. For smaller grids, illegal candidates are simply ignored. Although this is sometimes suboptimal (e.g. in a `*6` cage of size 2, the value 1 is possible in a grid of size 9, but not in a grid of size 3), grids of size ≤8 are solved almost instantly anyway.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgijs-pennings%2Fkenken-solver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgijs-pennings%2Fkenken-solver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgijs-pennings%2Fkenken-solver/lists"}