Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (def max-path-length 10)
- (defn get-paths
- ([current end] (get-paths current end [] 0))
- ([current end path depth]
- (if (= current end)
- (concat path [current])
- (let [neighbours (filter #(not (lazy-contains? (flatten path) %1))
- (get-neighbours current))]
- (if (or (= (count neighbours) 0)
- (>= depth max-path-length))
- (concat path [nil])
- (map (fn [item]
- (get-paths item end (concat path [current]) (+ depth 1)))
- neighbours))))))
- (defn get-shortest-path [start end]
- (apply min-key count
- (filter #(and (seq? %1) (= (last %1) end))
- (tree-seq seq? seq (get-paths start end)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement