Re: Topological sort

2018-06-15 Thread Matching Socks
user> (topological-sort {0 [1] 1 [2 3] 2 [3] 3 []}) (3 2 0 1) ! -- 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 - plea

Re: Topological sort

2009-11-16 Thread Nick Day
brilliant, this has been very helpful - thanks to both for taking the time to answer! On Nov 12, 6:06 am, John Harrop jharrop...@gmail.com wrote: On Wed, Nov 11, 2009 at 2:04 PM, Nick Day nicke...@gmail.com wrote: Hi, I've been trying to implement a topological sort and have been

Re: Topological sort

2009-11-16 Thread Christophe Grand
Just for the fun of writing it: (defn topological-sort [x] (mapcat #(for [[k v] % :when (empty? v)] k) (take-while seq (iterate #(into {} (for [[k v] % :when (seq v)] [k (mapcat % v)])) x user= (topological-sort {1 [2 3] 2 [3] 3 []}) (3 2 1) Note that it's not the same

Topological sort

2009-11-11 Thread Nick Day
Hi, I've been trying to implement a topological sort and have been struggling a bit. I have a map of symbol vs collection of symbols like: {a [b c], b [c], c [nil]} which can be read as 'a' depends on 'b' and 'c', 'b' depends on 'c' and 'c' doesn't depend on anything. I've been trying to write

Re: Topological sort

2009-11-11 Thread jan
Nick Day nicke...@gmail.com writes: I've been trying to implement a topological sort and have been struggling a bit. I have a map of symbol vs collection of symbols like: {a [b c], b [c], c [nil]} which can be read as 'a' depends on 'b' and 'c', 'b' depends on 'c' and 'c' doesn't depend

Re: Topological sort

2009-11-11 Thread John Harrop
On Wed, Nov 11, 2009 at 2:04 PM, Nick Day nicke...@gmail.com wrote: Hi, I've been trying to implement a topological sort and have been struggling a bit. I have a map of symbol vs collection of symbols like: {a [b c], b [c], c [nil]} which can be read as 'a' depends on 'b' and 'c', 'b