{"id":23508789,"url":"https://github.com/lovasko/dover","last_synced_at":"2025-05-13T15:35:05.186Z","repository":{"id":15034237,"uuid":"17760098","full_name":"lovasko/dover","owner":"lovasko","description":"Sudoku M*N Solver","archived":false,"fork":false,"pushed_at":"2015-03-10T06:42:48.000Z","size":204,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-25T11:32:44.604Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lovasko.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}},"created_at":"2014-03-14T20:57:31.000Z","updated_at":"2017-04-09T17:20:37.000Z","dependencies_parsed_at":"2022-08-29T03:00:45.166Z","dependency_job_id":null,"html_url":"https://github.com/lovasko/dover","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/lovasko%2Fdover","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovasko%2Fdover/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovasko%2Fdover/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovasko%2Fdover/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lovasko","download_url":"https://codeload.github.com/lovasko/dover/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239188698,"owners_count":19597032,"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-12-25T11:32:10.183Z","updated_at":"2025-02-16T19:44:29.174Z","avatar_url":"https://github.com/lovasko.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sudoku Solver\nSudoku `M*N` solver written in Prolog. Puzzles solved by this program are\nalways of a square size, with possibility of internal blocks having rectangle\nsize. Therefore a `3*4` sudoku will result in a `12*12` puzzle divided into 4\nblocks horizontally and 3 blocks vertically. Numbers contained range from 1 to\n12. The solver always yields all puzzle solutions. It is also possible to\nverify a solution by querying the solver with already filled puzzle.\n\n## Build\n```\n$ make\n```\n\n## Input\nThe solver expects the input file containing the puzzle to be in a specific\nformat:\n\nFirst line of the file must contain `width` and `height` of the sudoku with a\ndot (`.`) following each number. Both numbers must be unsigned integers. As\nmentioned in the initial paragraph, they merely denote the size of the\n*internal sudoku block* and not the whole sudoku size.\n\nExample:\n```\n2. 3.\n```\n\nFollowing the size declaration, a matrix of actual puzzle numbers, each\nfollowed by a dot, is expected.\nIn case of an unsolved field, `0` should take its place. Numbers in fields have\nto be from the interval `1..N*M`.\n\nExample:\n```\n0. 1. 0. 0. 0. 0.\n2. 0. 0. 0. 0. 0.\n0. 0. 0. 4. 0. 0.\n0. 0. 3. 0. 0. 0.\n0. 0. 0. 0. 5. 0.\n0. 0. 0. 0. 0. 6.\n```\n\n## Algorithms\nThere are two basic approaches used in this program. First, the static solving\nalgorithm, which creates a list of fields at first, and than backtracks thought\nthis list, always inserting correct values to the puzzle. During the first\ncomputation, no actual data modification is made and the heuristic method does\nnot take the values to account.\n\nOn the other hand, dynamic solving algorithm modifies actual puzzle data during\nits run. The heuristic method is based on field values.  Common code shared\nbetween these algorithms include sudoku puzzle `get`/`set` API calls and\npredicates concerning field correctness.\n\n### Static algorithms\nThe algorithm can be divided into two steps. First step is creating list of\nfields that were not pre-solved. Order of fields in this list based on\nheuristic approach.\n\nEach individual technique is described in its subsection. Second step is using\nProlog’s internal back-tracking engine to try to fill in each field, element by\nelement.\n\n#### Relatives\nThis heuristic approach sorts fields by following criterion: more fields in\nsame column, row or area already solved or added to list. These all are called\nthe *relatives*. In each step, it chooses the one with the most relatives.\n\n#### Neighbours\nThis heuristic approach sorts fields by following criterion: more fields solved\nor added to list from adjacent fields. These all are called the *neighbours*.\nIn each step, it chooses the one with the most neighbours.\n\n### Adhoc (Dynamic Algorithm)\nIn each step of this algorithm, all yet unsolved fields are evaluated by\nheuristic - fields with less possible correct values are ranked higher - and\nthan filled in. No list is being created, the actual puzzle is modified, so\neach step needs to recalculate the heuristic values.\n\n## Run\n```\n$ nz sudoku_file algorithm \n```\n\nWhere `sudoku_file` is a path to the puzzle and `algorithm` is one of the\npreviously mentioned techniques:\n * `relatives`\n * `neighbours`\n * `adhoc`\n\n## Testing\nThe software package employs a different solving solution provided by 3rd party\nwritten in C, that is located in the FreeBSD ports tree. This provides a\nunbiased testing method by using a different codebase. In order to run the\ntests, run the following commands:\n```\n$ cd test\n$ make\n$ make generate\n$ make solve\n```\nThe imported solver has `libncruses` as a dependency.\n\n## Prolog versions\nThe solver was successfully built, run and tested with following Prolog\nflavours:\n * GNU Prolog\n\n## Author\nDaniel Lovasko lovasko@freebsd.org\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flovasko%2Fdover","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flovasko%2Fdover","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flovasko%2Fdover/lists"}