{"id":19787398,"url":"https://github.com/adriacabeza/discretetomography","last_synced_at":"2026-03-02T22:07:22.129Z","repository":{"id":122837955,"uuid":"254115201","full_name":"adriacabeza/DiscreteTomography","owner":"adriacabeza","description":"Path Puzzles: Discrete Tomography with Prolog","archived":false,"fork":false,"pushed_at":"2020-04-08T15:10:57.000Z","size":795,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-11T03:41:51.165Z","etag":null,"topics":["logic-programming","prolog","puzzle-solving-game","puzzles","tomography"],"latest_commit_sha":null,"homepage":"","language":"Prolog","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adriacabeza.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-04-08T14:43:59.000Z","updated_at":"2024-04-26T13:59:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"60e789a9-6434-456e-994b-e177d1b7e958","html_url":"https://github.com/adriacabeza/DiscreteTomography","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/adriacabeza%2FDiscreteTomography","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adriacabeza%2FDiscreteTomography/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adriacabeza%2FDiscreteTomography/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adriacabeza%2FDiscreteTomography/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adriacabeza","download_url":"https://codeload.github.com/adriacabeza/DiscreteTomography/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241120181,"owners_count":19913011,"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":["logic-programming","prolog","puzzle-solving-game","puzzles","tomography"],"created_at":"2024-11-12T06:22:50.838Z","updated_at":"2026-03-02T22:07:22.084Z","avatar_url":"https://github.com/adriacabeza.png","language":"Prolog","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🧩 Discrete Tomography\n[![made-with-Prolog](https://img.shields.io/badge/Made%20with-Prolog-1f425f.svg)](http://commonmark.org)[![GitHub stars](https://img.shields.io/github/stars/adriacabeza/DiscreteTomography?style=social\u0026label=Star\u0026maxAge=2592000)](https://GitHub.com/adriacabeza/DiscreteTomography/stargazers/)\n\n\nThis problem is inspired by this [Path Puzzles: Discrete Tomography with a Path Constraint is Hard](https://erikdemaine.org/papers/PathPuzzles_JCDCGGG2017/paper.pdf) by Erik Demaine. It is also an attempt to start using Prolog more frequently and getting used to it.\n\n The probem can be considered as a puzzle consists of a (rectangular) grid of cells with two exits (or “doors”) on the boundary and numerical constraints on some subset of the rows and columns. A solution consists of a single non-intersecting path which starts and ends at two boundary doors and which passes through a number of cells in each constrained row and column equal to the given numerical clue. For example:\n\n\n\u003cp align=\"center\"\u003e\n \u003cimg src=\"docs/problem1.png\"/\u003e\n\u003c/p\u003e\n\n The input for this example would follow this structure:\n\n```\n6 # size of a side of the square\n3 4 4 3 4 3 # input of the X axis\n6 2 3 2 2 6 # inputs of the Y axis\n0 0 # starting point\n6 6 # goal\n```\n\nand here your output:\n\n```\n(0,0), (1,0), (2,0), (3,0), (4,0), (5,0), (5,1), (4,1), (4,2), (3,2), (2,2), (2,3), (1,3), (1,4), (0,4), (0,5), (1,5), (2,5), (3,5), (4,5), (5,5) \n```\n\n## First problem\nInput of the first problem:\n```\n6 \n5 3 3 4 3 5 \n5 3 5 1 5 4\n0 5\n1 0 \n```\nThe solution can be found at first.pl. \n```prolog\n?- [first].\ntrue.\n?- go(0,5,1,0,[w(0,5)],Path,[1,0,0,0,0,0], [0,0,0,0,0,1]).\nFinal path:[w(0,5),w(0,4),w(1,4),w(2,4),w(2,5),w(3,5),w(4,5),w(4,4),w(5,4),w(5,3),w(5,2),w(5,1),w(5,0),w(4,0),w(3,0),w(3,1),w(3,2),w(2,2),w(1,2),w(0,2),w(0,1),w(0,0),w(1,0)]\n```\n\n## Second problem\nNow we have some cells that we should avoid in our path. Let's try with a bigger one, input:\n```\n8\n6 4 2 4 8 5 7 7\n6 7 8 7 5 5 4 1\n0 5\n4 7\n# cells to be avoided (x,y)\n3 1 \n5 5 \n0 6\n1 6 \n0 7\n2 6 \n2 7\n7 7 \n6 7\n1 5\n2 5\n1 7\n2 6 \n```\nThe solution can be found at second.pl. \n```prolog\n?- [second].\ntrue.\n\n?- go(0,5,4,7,[w(0,5)],Path,[1,0,0,0,0,0,0,0], [0,0,0,0,0,1,0,0]).\nFinal path:[w(0,5),w(0,4),w(0,3),w(1,3),w(1,2),w(0,2),w(0,1),w(0,0),w(1,0),w(1,1),w(2,1),w(2,2),w(3,2),w(3,3),w(3,4),w(3,5),w(4,5),w(4,4),w(4,3),w(5,3),w(6,3),w(6,2),w(6,1),w(5,1),w(5,2),w(4,2),w(4,1),w(4,0),w(5,0),w(6,0),w(7,0),w(7,1),w(7,2),w(7,3),w(7,4),w(6,4),w(6,5),w(7,5),w(7,6),w(6,6),w(5,6),w(4,6),w(4,7)]\n```\n\n### Requirements\n\nIn the case that you do not want to install any Prolog programming environment, like SWI-Prolog, you can use the Dockerfile:\n\n```\ndocker build -t prolog . \u0026\u0026\ndocker run -it -d -v PATH_TO_REPOSITORY:/workspace prolog \u0026\u0026\ndocker exec -it name_of_container zsh\nswipl\n```\n\n### 👀 Spoiler for the second one\n\n Notice that if we did not insert some cells to be avoided we could have several good results, for example this two would be valid for the question (the real solution is the one in the right):\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"docs/maze1.jpg\" height=400\u003e\u003c/img\u003e\n\u003cimg src=\"docs/maze2.jpg\" height=400\u003e\u003c/img\u003e\n\u003c/p\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadriacabeza%2Fdiscretetomography","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadriacabeza%2Fdiscretetomography","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadriacabeza%2Fdiscretetomography/lists"}