Thanks. That looks very interesting. > ;; adjacency list > {:a [:b] :b [:c :d] :c [:e] :d [:e]}
For some reason, I have trouble constructing this recursively. I seem to always end up with something like this: user> (build-tree :a :e) (:a (:b (:c (:e)) (:d (:e)))) (defn build-tree [from to] (cons from (for [c (candidates from to)] (build-tree c to)))) I have a start key (:a) and an end key (:e). For each key, I can get candidates: user> (candidates :a :e) (:b) user> (candidates :b :e) (:c :d) user> (candidates :c :e) (:e) user> (candidates :d :e) (:e) user> (candidates :e :e) () On 19 Aug, 16:12, Justin Kramer <jkkra...@gmail.com> wrote: > There are many ways one could model a tree/graph: > > ;; collection of edges > [[:a :b] [:b :c] [:b :d] [:c :e] [:d :e]] > > ;; adjacency list > {:a [:b] :b [:c :d] :c [:e] :d [:e]} > > If you're looking for a pre-made solution, the loom graph library > (https://github.com/jkk/loom) may work: > > (ns example > (:use [loom.graph :only [digraph]] > [loom.alg :only [shortest-path]])) > > (def dg (digraph {:a [:b] :b [:c :d] :c [:e] :d [:e]})) > > (shortest-path dg :a :e) > ; => (:a :b :c :e) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en