Skip to content

Instantly share code, notes, and snippets.

@fffej
Created July 4, 2009 12:36
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 fffej/140555 to your computer and use it in GitHub Desktop.
Save fffej/140555 to your computer and use it in GitHub Desktop.
(defn sorter
"Return a combiner function that sorts according to cost-fn"
[cost-fn]
(fn [new old]
(sort (fn [n o] (< (cost-fn n) (cost-fn o))) (concat new old))))
(defn best-first-search
"Search lowest cost states first until goal is reached"
[start goal? successors cost-fn]
(tree-search (list start) goal? successors (sorter cost-fn)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment