Skip to content

Instantly share code, notes, and snippets.

@spoon16
Created May 16, 2015 02:22
Show Gist options
  • Save spoon16/c0543a7431c47249a2cb to your computer and use it in GitHub Desktop.
Save spoon16/c0543a7431c47249a2cb to your computer and use it in GitHub Desktop.
make graph
;; I feel like this should be less lines
(defn add-edge
[graph edge]
(let [parts (clojure.string/split edge #",")
from (first parts)
to (second parts)
graph (if (not (contains? graph from))
(assoc-in graph [from] #{})
graph)
graph (if (not (contains? graph to))
(assoc-in graph [to] #{})
graph)]
(update-in graph [from] conj to)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment