Skip to content

Instantly share code, notes, and snippets.

@tirkarthi
Created October 27, 2017 05:48
Show Gist options
  • Save tirkarthi/df7b99ad5d9d04745b67040093598984 to your computer and use it in GitHub Desktop.
Save tirkarthi/df7b99ad5d9d04745b67040093598984 to your computer and use it in GitHub Desktop.
(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