Created
May 16, 2015 02:22
-
-
Save spoon16/c0543a7431c47249a2cb to your computer and use it in GitHub Desktop.
make graph
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
;; 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