Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (declare helper)
- (defn- dfs [graph start end n acc]
- (if (= n end) (conj acc end)
- (let [ns (seq (disj (get graph n) (peek acc)))]
- (if (empty? ns)
- nil
- (helper graph start end ns (conj acc n))))))
- (defn- helper [graph start end ns acc]
- (if (empty? ns)
- nil
- (let [p (dfs graph start end (first ns) acc)]
- (if p
- p
- (recur graph start end (rest ns) acc)))))
- (defn findpath [graph start goal]
- (dfs graph start goal start []))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement