Oops, renamed the function: get-edges = candidates->edges. Justin
On Friday, August 19, 2011 4:03:27 PM UTC-4, Ulrik Sandberg wrote: > > And get-edges? > > On 19 Aug, 20:52, Justin Kramer <jkkr...@gmail.com> wrote: > > Here's another way, which constructs a sequence of edges using > candidates, > > which are then fed into reduce to build an adjacency list. > > > > (defn candidates->edges [candidates from to] > > (when-let [kids (seq (candidates from to))] > > (concat (for [k kids] [from k]) > > (mapcat #(get-edges candidates % to) kids)))) > > > > (defn edges->adj [edges] > > (reduce > > (fn [adj [a b]] > > (update-in adj [a] conj b)) > > {} edges)) > > > > (edges->adj (candidates->edges candidates :a :e)) > > ; => {:d (:e), :c (:e), :b (:d :c), :a (:b)} > > > > This doesn't handle cycles. > > > > Justin -- 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