Created
February 22, 2009 23:22
-
-
Save bracki/68690 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use 'clojure.contrib.seq-utils) | |
(def graph {:a [:b], :b [:a :c], :c [:b :d], :d [:c]}) | |
(defn find-path | |
"Find a path between a start and an end node." | |
([g start end] | |
(if (contains? g start) | |
(find-path g start end []))) | |
([g start end path] | |
(let [p (conj path start)] | |
(if (= start end) | |
p | |
(continue-path g (g start) end p))))) | |
(defn continue-path [g [n & ns] end path] | |
(if n | |
(or (and (not (includes? path n)) | |
(find-path g n end path)) | |
(recur g ns end path)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment