{"id":15415862,"url":"https://github.com/davidje13/nonogram","last_synced_at":"2025-03-20T13:20:52.244Z","repository":{"id":151511175,"uuid":"311784773","full_name":"davidje13/Nonogram","owner":"davidje13","description":"Nonogram / picross editor, player, and solver","archived":false,"fork":false,"pushed_at":"2024-02-26T12:41:17.000Z","size":199,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-08T14:02:52.336Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://davidje13.github.io/Nonogram/","language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davidje13.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":"2020-11-10T21:06:50.000Z","updated_at":"2023-12-04T18:23:57.000Z","dependencies_parsed_at":"2023-11-28T01:27:21.218Z","dependency_job_id":"161817ea-0cba-4ab9-bf82-bda2c6ecc168","html_url":"https://github.com/davidje13/Nonogram","commit_stats":{"total_commits":85,"total_committers":1,"mean_commits":85.0,"dds":0.0,"last_synced_commit":"243f0f6f57af6473509d33d6132b9e94cd50e130"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidje13%2FNonogram","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidje13%2FNonogram/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidje13%2FNonogram/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidje13%2FNonogram/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidje13","download_url":"https://codeload.github.com/davidje13/Nonogram/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244618448,"owners_count":20482319,"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-01T17:10:02.966Z","updated_at":"2025-03-20T13:20:52.216Z","avatar_url":"https://github.com/davidje13.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nonogram\n\nA nonogram (also known as picross) solver and web player.\n\nIncludes an editor with automatic detection of ambiguous games, and a player with\nthe ability to show hints.\n\nSolving uses various techniques: the simplest applies a 1D solver to each rule in\nturn (described below). If this cannot make progress, a map of direct implications\nis created and traversed to find obvious contradictions and tautologies. If this\nalso fails to resolve any squares, the solver falls back to forking the game state\nby setting a cell to both ON and OFF, and continuing each branch until a\ncontradiction is found on one of them (or, if no contradictions are found on either\nbranch, it marks the game as ambiguous).\n\nWhen offering hints, several 'simpler' methods are also used, with their results\nbeing preferred as easier for players to understand.\n\n## Running\n\n```bash\n./bin/solve.mjs games/football.json\n```\n\n\u003e ```\n\u003e Solving games/football.json\n\u003e                                1  1\n\u003e                                1  1     3     3\n\u003e                          3  2  1  3  2  3  5  1  2  3     2  2\n\u003e                 1  2  2  1  1  2  1  6  9  3  2  1  3  2  1  2  2\n\u003e              2  2  3  3  1  1  2  3  4  1  2  2  7  2  4  2  1  2  1  1\n\u003e           3                               ## ## ##\n\u003e           5                            ## ## ## ## ##\n\u003e         3 1                            ## ## ##    ##\n\u003e         2 1                            ## ##       ##\n\u003e       3 3 4                   ## ## ##    ## ## ##    ## ## ## ##\n\u003e       2 2 7             ## ##       ## ##          ## ## ## ## ## ## ##\n\u003e       6 1 1       ## ## ## ## ## ##    ##          ##\n\u003e       4 2 2    ## ## ## ##          ## ##       ## ##\n\u003e         1 1                         ##          ##\n\u003e         3 1                      ## ## ##       ##\n\u003e           6                      ## ## ## ## ## ##\n\u003e         2 7    ## ##          ## ## ## ## ## ## ##\n\u003e       6 3 1 ## ## ## ## ## ##       ## ## ##    ##\n\u003e   1 2 2 1 1 ##    ## ##       ## ##    ##       ##\n\u003e     4 1 1 3          ## ## ## ##       ##    ##       ## ## ##\n\u003e       4 2 2                         ## ## ## ##    ## ##    ## ##\n\u003e       3 3 1                         ## ## ##       ## ## ##    ##\n\u003e         3 3                      ## ## ##             ## ## ##\n\u003e           3                   ## ## ##\n\u003e         2 1                   ## ##    ##\n\u003e\n\u003e Short image: LSJGLQRYQShD41JJX_QjekiFT8-SPTj3J0IIfSiK_ri16tDFuy00opFQpBLos\n\u003e Short rules: RSJH58Z7Dnyl9tWtZGp7r8XqjLwdrazUm-812Xl5kSoFuEelf7b7FW0LhH2lo-VloqQ\n\u003e Solving time: 140.1ms\n\u003e ```\n\n## Methods\n\n### Isolated Rules\n\nThe `isolated-rules` solver will resolve all possible cells based soely on one rule at\na time. The `perl-regexp` sub-solver will resolve all possible state from an individual\nrule.\n\nThe method is similar to a regular expression. At a high-level, each rule compiles to a\nregular expression which is applied to the current state of the row or column using a\nperl-like state machine. Then each cell is checked in reverse; if all state machine states\nfor the current cell which result in a successful match are of the same type, the cell's\ntype can be asserted. This method runs in `O(n^2)` time at worst (for `n` cells) and\nfor typical rules runs in closer to `O(n)` time.\n\nFor example:\n\n1. The rule is `[4, 2]` and the game state is `iyiiiiii`\n   (`y` is ON, `n` is OFF, `i` is indeterminate)\n2. The rule is compiled to (roughly):\n   ```\n   ^[ni]*[yi][yi][yi][yi][ni]+[yi][yi][ni]*$    \u003c-- regex interpretation\n   0 1    2   3   4   5   6    7   8   9   10   \u003c-- state number\n   ```\n   Which can also be visualised as a graph:\n   ```\n   0---1---2-3-4-5--6--7-8---9---10\n    \\ (_) /        (_)    \\ (_) /\n     \\___/                 \\___/\n   ```\n3. The regular expression state machine advances along the input, recording possible\n   states for each cell:\n   ```\n   ^  i  y  i  i  i  i  i  i  $  \u003c-- input\n   0--1--2--3--4--5--6--7--8     \u003c-- possible states for current cell (left-to-right)\n   |                / \\     \\\n   |               /    6--7 \\\n   |              |      \\    |\n    \\             |        6  |\n     \\            |           |\n      2--3--4--5--6--7--8--9-[10]\n   ```\n4. All valid paths are traced backwards from the end state. In this example the valid\n   paths are:\n   ```\n   ^  i  y  i  i  i  i  i  i  $  \u003c-- input\n   0--1--2--3--4--5--6--7--8     \u003c-- valid state paths\n    \\               /       \\\n     \\             /         \\\n      2--3--4--5--6--7--8--9-[10]\n\n   0  1  2  3  4  5  6  7  8  10 \u003c-- flattened states per cell\n      2  3  4  5  6  7  8  9\n   ```\n5. Each state has an associated cell type. Identify cells where all possible states\n   share the same cell type:\n   ```\n   ^  i  y  i  i  i  i  i  i  $  \u003c-- input\n   -  n  y  y  y  y  n  y  y  -  \u003c-- state cell types\n      y  y  y  y  n  y  y  n\n\n      ?  y  y  y  ?  ?  y  ?     \u003c-- resolved cell value\n   ```\n6. The output is `iyyyiiyi`.\n\nAs this solver only considers one rule at a time, it can get stuck in various\nsituations. When more than one rule is needed to make progress, another solver\nis required;\n\n### Implications\n\nThe `implications` solver will build a map of all the implications which can be\nresolved from considering one rule at a time:\n\n```\n(2,3) = ON  =\u003e (8,3) = OFF\n(2,3) = OFF =\u003e (2,2) = OFF\n(5,6) = ON  =\u003e (5,7) = ON\netc.\n```\n\nThis map is built using a 1D solver, as described above.\n\nIt will then traverse the resulting graph looking for contradictions. For example:\n\n```\n(1,1) = ON  =\u003e (1,2) = ON\n(1,2) = ON  =\u003e (2,2) = ON\n(1,1) = ON  =\u003e (2,1) = ON\n(2,1) = ON  =\u003e (2,2) = OFF\n```\n\nIf a graph contained these implications, cell (1,1) cannot be ON, as it would\ncause a contradiction in cell (2,2). As a result, the rule marks cell (1,1) as\nOFF.\n\nIn some cases, it may also find tautologies. For example:\n\n```\n(1,1) = ON  =\u003e (1,2) = OFF\n(1,2) = OFF =\u003e (2,2) = OFF\n(1,1) = OFF =\u003e (2,1) = ON\n(2,1) = ON  =\u003e (2,2) = OFF\n```\n\nIn this case, cell (2,2) must be OFF regardless of the value of cell (1,1).\n\nThe graph is searched to a configurable depth (infinite by default), but cannot\naccount for situations where two pieces of information in the same row or column\nmust be taken together to infer a third. For such situations, the final solver is\nrequired;\n\n### Fork\n\nThe `fork` solver is used as a last resort if no other solvers can make progress.\nIt picks an unknown cell which is likely to have a large impact on the game when\nresolved as ON or OFF, and splits the game into 2: one with the cell marked ON,\nand one with it marked OFF. Both branches then continue to be solved (and may\nsplit again recursively) until one of them reaches a conflict. The game then\ncontinues with the state from the other branch.\n\nIf both branches complete without a conflict, the game is ambiguous.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidje13%2Fnonogram","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidje13%2Fnonogram","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidje13%2Fnonogram/lists"}