{"id":20552221,"url":"https://github.com/mhrimaz/core-logic-exploration","last_synced_at":"2026-05-26T20:32:34.626Z","repository":{"id":178295693,"uuid":"95706046","full_name":"mhrimaz/core-logic-exploration","owner":"mhrimaz","description":"Exploration in Clojure core.logic","archived":false,"fork":false,"pushed_at":"2017-06-29T11:55:36.000Z","size":190,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-06T06:15:16.733Z","etag":null,"topics":["clojure","logic-programming"],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mhrimaz.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":"2017-06-28T19:50:58.000Z","updated_at":"2017-06-29T14:42:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"cf29ad7e-854c-4743-a16d-ba32f0364e4b","html_url":"https://github.com/mhrimaz/core-logic-exploration","commit_stats":null,"previous_names":["mhrimaz/core-logic-exploration"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mhrimaz/core-logic-exploration","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhrimaz%2Fcore-logic-exploration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhrimaz%2Fcore-logic-exploration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhrimaz%2Fcore-logic-exploration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhrimaz%2Fcore-logic-exploration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mhrimaz","download_url":"https://codeload.github.com/mhrimaz/core-logic-exploration/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhrimaz%2Fcore-logic-exploration/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33538659,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"ssl_error","status_checked_at":"2026-05-26T15:22:15.568Z","response_time":63,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["clojure","logic-programming"],"created_at":"2024-11-16T02:35:33.078Z","updated_at":"2026-05-26T20:32:34.605Z","avatar_url":"https://github.com/mhrimaz.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# core.logic Exploration\nExploration in Clojure core.logic\n# Getting Started\nOpen a Leiningen REPL and for importing core.logic type the following:\n```clojure\n(require '[clojure.core.logic :as logic])\n(require '[clojure.core.logic.pldb :as kb])\n(require '[clojure.core.logic.fd :as fd])\n```\n# Map Coloring\nThis problem is described in Artificial Intelligence: A Modern Approach book which is a CSP problem.\nHere is an image of the map:\n\n\n![Map Image](https://github.com/mhrimaz/core-logic-exploration/blob/master/MapColoring.PNG)\n## Solution\n```clojure\n(logic/run 4 [q]\n           (logic/fresh [WA NT SA Q NSW V T]\n             (logic/everyg #(logic/membero % [:RED :GREEN :BLUE]) [WA NT SA Q NSW V T])\n             (logic/!= WA NT)(logic/!= WA SA)(logic/!= NT SA)(logic/!= NT Q)\n             (logic/!= SA NSW)(logic/!= SA V)(logic/!= Q NSW)(logic/!= NSW V)\n             (logic/== q {:WA WA :NT NT :SA SA :Q Q :NSW NSW :V V :T T})\n           ))\n```\n\n\n![Map Image 1](https://github.com/mhrimaz/core-logic-exploration/blob/master/MapColoring1.png)\n\n\n![Map Image 2](https://github.com/mhrimaz/core-logic-exploration/blob/master/MapColoring2.png)\n\n# Simple Finite Domain Puzzle\nFind all the numbers between 2 and 13 such x and y which their negation is equal to 7 ( x - y = 7 )\n## Solution\n```clojure\n(logic/run* [q]\n            (logic/fresh [x y]\n                   (fd/in x y (fd/interval 2 13))\n                   (fd/- x y 7)\n                   (logic/== q [x y])))\n; =\u003e ([9 2] [10 3] [11 4] [12 5] [13 6])\n```\n# Cryptarithmetic Puzzle\nThis puzzle descirbed in Artificial Intelligence: A Modern Approach page 206. Each letter in a cryptarithmetic puzzle represents a different digit.\n\n\n![Cryptarithmetic Puzzle](https://github.com/mhrimaz/core-logic-exploration/blob/master/cryptarithmetic.png)\n\n\nThis would be represented as the global constraint Alldifferent (F, T, U, W, R, O)\nThe addition constraints on the four columns of the puzzle can be written as the following n-ary constraints:\n* O + O = R + 10 · C10\n* C10 + W + W = U + 10 · C100\n* C100 + T + T = O + 10 · C1000\n* C1000 = F\n\n\nWhere C10, C100, and C1000 are auxiliary variables representing the digit carried over into the tens, hundreds, or thousands column.\n\n## Solution\n```clojure\n(defn crypArethmeticPuzzle [q]\n  (logic/fresh [T W O F U R TWO FOUR]\n               (fd/in T W O F U R (fd/interval 0 9))\n               (fd/distinct [T W O F U R]) ; Alldiff ( T W O F U R )\n               (fd/in TWO (fd/interval 100 999)) ; TWO is a three digits number\n               (fd/in FOUR (fd/interval 1000 9999)) ; FOUR is a four digits number\n               \n               (fd/eq (= TWO (+ (* 100 T) (* 10 W) O))) ; TWO is consist of three digits which is T W O\n               (fd/eq (= FOUR (+ (* 1000 F) (* 100 O) (* 10 U) R))) ; FOUR is consist of four digits which is F O U R\n               (fd/eq (= (+ TWO TWO) FOUR)) ; Peace of Cake! TWO + TWO = FOUR\n               \n               (logic/== q [TWO TWO FOUR]) \n               ))\n; =\u003e #'user/crypArethmeticPuzzle\n\n(logic/run* [q]\n            (crypArethmeticPuzzle q))\n; =\u003e ([734 734 1468] [765 765 1530] \n; [836 836 1672] [846 846 1692] \n; [867 867 1734] [928 928 1856] [938 938 1876])\n```\n# Sudoku\nThe goal of Sudoku is to fill a 9×9 grid with numbers so that each row, column and 3×3 section contain all of the digits between 1 and 9. The constraints are:\n* Each column must contain one occurrence of each digit from 1–9.\n* Each row must contain one occurrence of each digit from 1–9.\n* Each 3 x 3 subsection must contain one occurrence of each digit from 1–9\nThis is the example that we want to solve:\n\n![Sudoku](https://github.com/mhrimaz/core-logic-exploration/blob/master/Sudoku.png)\n\n## Solution\n```clojure\n; Problem representation\n; https://www.sudoku.ws/hard-20.htm\n(def s1 '[1 - - - 7 - - 3 -\n          8 3 - 6 - - - - -\n          - - 2 9 - - 6 - 8\n          6 - - - - 4 9 - 7\n          - 9 - - - - - 5 -\n          3 - 7 5 - - - - 4\n          2 - 3 - - 9 1 - -\n          - - - - - 2 - 4 3\n          - 4 - - 8 - - - 9])\n\n(defn rowify [board]\n  (-\u003e\u003e board\n       (partition 9)\n       (map vec)\n       vec))\n       \n(defn colify [rows]\n  (apply map vector rows))\n  \n(defn gridify [rows]\n  (partition 9\n             (for [row (range 0 9 3)\n                   col (range 0 9 3)\n                   x (range row (+ row 3))\n                   y (range col (+ col 3))]\n               (get-in rows [x y]))))  \n               \n(def initLogicBoard #(repeatedly 81 logic/lvar))\n\n(defn init [[lv \u0026 lvs] [cell \u0026 cells]]\n  \"bind known number values to certain logic variable\"\n  (if lv\n    (logic/fresh []\n                 (if (= '- cell)\n                   logic/succeed\n                   (logic/== lv cell))\n                 (init lvs cells))\n    logic/succeed))\n\n(defn solveSudoku [board]\n  (let [lvars (initLogicBoard)\n        rows (rowify lvars)\n        cols (colify rows)\n        grids (gridify rows)]\n    (logic/run 1 [q]\n               (init lvars board)\n               (logic/everyg #(fd/in % (fd/interval 1 9)) lvars)\n               (logic/everyg fd/distinct rows)\n               (logic/everyg fd/distinct cols)\n               (logic/everyg fd/distinct grids)\n               (logic/== q lvars))))\n               \n(solveSudoku s1)              \n\n(comment \n  \"\n  1 6 9 8 7 5 4 3 2\n  8 3 4 6 2 1 7 9 5\n  5 7 2 9 4 3 6 1 8\n  6 2 5 1 3 4 9 8 7\n  4 9 8 2 6 7 3 5 1\n  3 1 7 5 9 8 2 6 4\n  2 8 3 4 5 9 1 7 6\n  9 5 6 7 1 2 8 4 3\n  7 4 1 3 8 6 5 2 9 \")\n  \n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmhrimaz%2Fcore-logic-exploration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmhrimaz%2Fcore-logic-exploration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmhrimaz%2Fcore-logic-exploration/lists"}