Skip to content

Instantly share code, notes, and snippets.

@ponzao
Created August 20, 2012 09:41
Show Gist options
  • Save ponzao/3402701 to your computer and use it in GitHub Desktop.
Save ponzao/3402701 to your computer and use it in GitHub Desktop.
(require 'clojure.set)
(def connections
["3-4"
"4-9"
"8-0"
"2-3"
"5-6"
"2-9"
"5-9"
"7-3"
"4-8"
"5-6"
"0-2"
"6-1"
"11-12"
"11-16"])
(defn path->pair
[path]
(map #(Integer/parseInt %) (.split path "-")))
(defn graph-find
[connections x]
(some (partial clojure.set/subset? x)
(reduce (fn [acc path]
(let [pair (path->pair path)
pred (partial some (set pair))
[connected disconnected] ((juxt filter remove) pred acc)]
(set (cons (set (apply concat pair connected)) disconnected))))
#{}
connections)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment