+(defn distances-from [tree node]
+ (letfn [(path-rc [dist tree node]
+ (let [seen? #(some? (get-in tree [% :dist]))
+ neighbors (remove (some-fn nil? seen?)
+ (cons (get-in tree [node :parent])
+ (get-in tree [node :children])))]
+ (as-> tree it
+ (assoc-in it [node :dist] dist)
+ (reduce #(path-rc (inc dist) %1 %2) it neighbors))))]
+ (path-rc 0 tree node)))
+
+(defn assign-depth [tree]
+ (let [is-root? #(nil? (get-in tree [% :parent]))
+ root (first (filter is-root? (keys tree)))]
+ (letfn [(depth-rc [depth tree root]
+ (as-> tree it
+ (assoc-in it [root :depth] depth)
+ (reduce #(depth-rc (inc depth) %1 %2)
+ it (get-in tree [root :children]))))]
+ (depth-rc 0 tree root))))
+