Skip to content

Instantly share code, notes, and snippets.

@martintrojer
Forked from swannodette/gist:3341330
Created August 13, 2012 17:35
Show Gist options
  • Save martintrojer/3342658 to your computer and use it in GitHub Desktop.
Save martintrojer/3342658 to your computer and use it in GitHub Desktop.
clique.clj
;; http://dosync.posterous.com/know-your-bounds
(defrel connected ^:index x ^:index y)
(facts connected [[1 2] [1 5]])
(facts connected [[2 1] [2 3] [2 5]])
(facts connected [[3 2] [3 4]])
(facts connected [[4 3] [4 5] [4 6]])
(facts connected [[5 1] [5 2] [5 4]])
(facts connected [[6 4]])
(defne connected-to-allo
"Ensure that vertex v is connected to all vertices
vs."
[v vs]
([_ ()])
([_ [vh . vr]]
(connected v vh)
(connected-to-allo v vr)))
(defne all-connected-to-allo
"Collect all cliques in l. l must be bounded to ensure
termination."
[l]
([()])
([[h . t]]
(connected-to-allo h t)
(all-connected-to-allo t)))
;; ----
(run-nc* [q]
(fresh [a b d]
(== q (llist a b d))
(bounded-listo q 6)
(all-connected-to-allo q)))
;; => ((2 1) (3 2) ... (5 2 1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment