Skip to content

Instantly share code, notes, and snippets.

@thiagomoretto
Created August 10, 2015 00:56
Show Gist options
  • Save thiagomoretto/eebb1120ebca8d245350 to your computer and use it in GitHub Desktop.
Save thiagomoretto/eebb1120ebca8d245350 to your computer and use it in GitHub Desktop.
Breadth-first
(defn bfs [sz ef ff]
"Initial state sz, expansion function ef [s] and feasibility function ff [s]"
(loop [queue (conj clojure.lang.PersistentQueue/EMPTY sz)
ef ef
ff ff]
(if (seq queue)
(let [nx (peek queue)]
(if (ff nx) nx (recur (into (pop queue) (ef nx)) ef ff)))
nil)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment