Skip to content

Instantly share code, notes, and snippets.

@stathissideris
Created December 19, 2012 02:42
Show Gist options
  • Save stathissideris/4333906 to your computer and use it in GitHub Desktop.
Save stathissideris/4333906 to your computer and use it in GitHub Desktop.
What ditaa would look like in Clojure
(require '[clojure.string :as string])
(defn gget [grid [x y]]
(get-in grid [y x] \space))
(defn gassoc [grid [x y] v]
(assoc-in grid [y x] v))
(defn dimensions [grid]
[(apply max (map count grid)) (count grid)])
(defn print-grid [grid]
(doseq [row grid]
(println (apply str row))))
(defn load-grid [file]
(-> file
(slurp)
(string/split #"\r?\n")
(->> (map vec))
(vec)))
(defn non-recursive-nodes [g]
(apply disj (set (:nodes g)) (apply concat (self-recursive-sets g))))
(defn merge-graph [a b]
(struct-map directed-graph
:nodes (into #{} (concat (:nodes a) (:nodes b)))
:neighbors (fn [n] (concat ((:neighbors a) n)
((:neighbors b) n)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment