Skip to content

Instantly share code, notes, and snippets.

@raek
Created August 23, 2011 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raek/1165579 to your computer and use it in GitHub Desktop.
Save raek/1165579 to your computer and use it in GitHub Desktop.
(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