{"id":22789019,"url":"https://github.com/blynn/dlx","last_synced_at":"2025-04-16T01:37:00.064Z","repository":{"id":66381600,"uuid":"14354323","full_name":"blynn/dlx","owner":"blynn","description":"Library that solves the exact cover problem using Dancing Links, also known as DLX.","archived":false,"fork":false,"pushed_at":"2022-02-16T04:27:19.000Z","size":62,"stargazers_count":50,"open_issues_count":1,"forks_count":11,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-29T03:32:07.497Z","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":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/blynn.png","metadata":{"files":{"readme":"README.asciidoc","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2013-11-13T04:58:03.000Z","updated_at":"2024-04-06T01:19:10.000Z","dependencies_parsed_at":"2023-10-20T18:29:29.135Z","dependency_job_id":null,"html_url":"https://github.com/blynn/dlx","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/blynn%2Fdlx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blynn%2Fdlx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blynn%2Fdlx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blynn%2Fdlx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blynn","download_url":"https://codeload.github.com/blynn/dlx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249182779,"owners_count":21226121,"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-12T01:40:42.236Z","updated_at":"2025-04-16T01:37:00.048Z","avatar_url":"https://github.com/blynn.png","language":"C","funding_links":[],"categories":["Utilities","公用事业"],"sub_categories":["YAML"],"readme":"= The DLX Library =\nBen Lynn \u003cblynn@cs.stanford.edu\u003e\n2013\n\n== The DLX library ==\n\nThe DLX library solves instances of the exact cover problem, using Dancing\nLinks (Knuth's Algorithm X).\n\nAlso included are programs that use the library:\n\n * Suds: a sudoku solver that represents a sudoku puzzle as an exact cover problem instance.\n * Grizzly: a \"logic grid puzzle\" solver. Requires my https://github.com/blynn/blt[BLT library].\n \n== Building everything ==\n\nThe following should work:\n\n $ git clone https://github.com/blynn/blt\n $ git clone https://github.com/blynn/dlx\n $ cd dlx\n $ make\n $ ./suds \u003c platinum.sud\n $ ./grizzly \u003c zebra.gr\n\n== DLX example ==\n\nConsider the following table, where the last column is optional:\n\n[cols=\"s,3*\",options=\"header\",width=\"10%\"]\n|=======\n| |0|1|2\n|0|1|0|1\n|1|0|1|1\n|2|0|1|0\n|3|1|1|0\n|=======\n\nSince covering the last column is optional, there are two solutions:\n\n  1. Rows 0 and 2.\n  2. Row 3 by itself.\n\nThe following program should confirm this.\n\n------------------------------------------------------------------------------\n#include \u003cstdio.h\u003e\n#include \"dlx.h\"\nint main() {\n  // Initialize a new exact cover instance.\n  dlx_t dlx = dlx_new();\n\n  // Setup the rows\n  dlx_set(dlx, 0, 0);\n  dlx_set(dlx, 0, 2);\n  dlx_set(dlx, 1, 1);\n  dlx_set(dlx, 1, 2);\n  dlx_set(dlx, 2, 1);\n  dlx_set(dlx, 3, 0);\n  dlx_set(dlx, 3, 1);\n\n  // Mark the last column as optional.\n  dlx_mark_optional(dlx, 2);\n\n  void f(int row[], int n) {\n    printf(\"Solution: rows:\");\n    for(int i = 0; i \u003c n; i++) {\n      printf(\" %d\", row[i]);\n    }\n    printf(\"\\n\");\n  }\n  dlx_forall_cover(dlx, f);\n\n  // Clean up.\n  dlx_clear(dlx);\n  return 0;\n}\n------------------------------------------------------------------------------\n\n== Suds ==\n\nSuds reads from standard input and ignores all characters except for the digits\nand \".\". Nonzero digits represent themsleves and \"0\" or \".\" represents an\nunknown digit.\n\nShows step-by-step reasoning when run with `-v`.\n\nSee `platinum.sud` for an example input.\n\n== Grizzly ==\n\nWe view a logic grid puzzle as follows. Given a MxN table of distinct symbols\nand some constraints, for each row except the first, we are to permute its\nentries so that the table satisfies the constraints.\n\nGrizzly reads a logic grid puzzle from standard input and prints all its\nsolutions. If run with `--alg=brute`, Grizzly employs brute force instead of\nDancing Links.\n\nThe input should begin with M lines of N space-delimited fields, terminated by\n\"%%\" on a single line by itself. This should be followed by the constraints.\nEach constraint is described by a single line containing space-delimited\nfields. The first field is the constraint type, and the remainder are\nsymbols.\n\nAn example 2x3 puzzle:\n\n------------------------------------------------------------------------------\nAlice Bob Carol\nbandoneon kazoo theremin\n%%\n! Carol kazoo\n= Alice theremin\n------------------------------------------------------------------------------\n\nThe meaning of each constraint type is as follows:\n\n[cols=\"1,80\"]\n|============================================================================\n|  !  | given symbols lie in distinct columns\n|  =  | given symbols lie in the same column\n|  \u003c  | column of 1st symbol lies left of column of 2nd symbol\n|  \u003e  | column of 1st symbol lies right of column of 2nd symbol\n|  A  | column of 1st symbol is adjacent to column of 2nd symbol\n|  1  | column of 1st symbol lies one to the left of the column of 2nd symbol\n|  i  | column of 1st symbol contains exactly one of the following symbols\n|  ^  | at most one column contains 2 or more of the given symbols\n|  p  | first 2 symbols lie in distinct columns; next 2 symbols lie in distinct columns; each column contains exactly 0 or 2 of these 4 symbols\n|  X  | group symbols in pairs; at most one of these pairs lie in the same column\n|============================================================================\n\nThus in the above example, the original logic puzzle might have stipulated that\n\"Carol does not play the kazoo.\" and \"Alice plays the theremin.\"\n\nGrizzly prints the transpose of the solution, possibly out of order.\nIn other words, the symbols in the same row in the input are instead in the\nsame _column_ in the output, and the first symbols of the rows in the output\nmay be in a different order than the symbols in the first row of the input.\n\n  Alice theremin\n  Carol bandoneon\n  Bob kazoo\n\nSee `zebra.gr`, which encodes http://en.wikipedia.org/wiki/Zebra_Puzzle[the\nZebra Puzzle].\n\nI'm still working on the constraint language. I chose one-character commands\nfor easy typing and parsing.\n\nOriginally, \"=\" meant that one column contained at least 2 of the given\nsymbols. This is easy to check in the brute force solver, and allows some\npuzzles to be encoded with fewer types of rules, but it is a troublesome\nconstraint for the Dancing Links solver so I changed the meaning to the above.\n\nThe \"p\" constraint (I chose \"p\" for \"pairs\") can be rewritten as two \"i\"\nconstraints plus one \"!\" constraint, but numerous puzzles contained clues\ndescribing equalities between sets of size 2, such as: \"Of Jack and Jill, one\nis wearing mukluks and the other was born in Timbuktu.\"\n\nI found no puzzles depended on the order of the input symbols in any row apart\nfrom the first, so I shelved my original plans to support this. Puzzles only\nseem to care about the order of the symbols in the first row.\n\nThe \"X\" constraint functions as a catch-all to handle constraints that seem\ntricky to otherwise describe.\n\n== License ==\n\nSee `COPYING` for details.\n\nThis program is free software; you can redistribute it and/or modify it under\nthe terms of the GNU General Public License as published by the Free Software\nFoundation; either version 3 of the License, or (at your option) any later\nversion.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY\nWARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A\nPARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with\nthis program; if not, write to the Free Software Foundation, Inc., 51 Franklin\nStreet, Fifth Floor, Boston, MA 02110-1301  USA\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblynn%2Fdlx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblynn%2Fdlx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblynn%2Fdlx/lists"}