Created
October 27, 2017 05:48
-
-
Save tirkarthi/df7b99ad5d9d04745b67040093598984 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns foo.coloring-tn | |
(:require [clojure.core.logic :refer :all] | |
[clojure.core.logic.pldb :as pldb])) | |
(def facts | |
(pldb/db | |
[color 'red] | |
[color 'green] | |
[color 'blue] | |
[color 'pink] | |
)) | |
(defn neighbor [state-a state-b] | |
(all | |
(color state-a) | |
(color state-b) | |
(!= state-a state-b))) | |
(let [states '[A B C] | |
res (pldb/with-db facts (run 1 [q] | |
(fresh [A B C] | |
(neighbor A B) | |
(neighbor B C) | |
(== q [A B C]))))] | |
(map #(zipmap states %) res)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment