Created
August 23, 2011 15:56
-
-
Save raek/1165579 to your computer and use it in GitHub Desktop.
This file contains 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
(defn find-paths | |
"All paths without repeating vertices in a given graph" | |
[g] | |
(letfn | |
[(search-tree [v p paths] | |
(if ((set p) v) | |
paths | |
(let [p+ (cons v p)] | |
(search (g v) p+ (conj paths p+))))) | |
(search [vs p paths] | |
(reduce #(search-tree %2 p %1) paths vs))] | |
(search (range 0 (count g)) [] #{}))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment