Created
August 31, 2016 22:28
-
-
Save hadielmougy/c5100ea409581dedc5e41f2e8bc842a6 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
(defn node [g] | |
(set (flatten g))) | |
(defn adjList [g] | |
(into {} (vec ((fn [m] into {} (for [[k v]m] {k (node v)}))(group-by first g))))) | |
(defn connected? [g a b] | |
(loop [n (a g) | |
v #{}] | |
(let [diff (clojure.set/difference n v)] | |
(if (clojure.set/superset? v n) false | |
(if (contains? n b) true | |
(recur | |
(flatten (into #{} (vec (map #(replace {% (% g)} n) n)))) | |
;;(into #{} (vec ((fn [m] into {}(for [x m](x g)))n))) | |
(set (concat n v)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment