Skip to content

Instantly share code, notes, and snippets.

Created August 11, 2011 08:31
Show Gist options
  • Save anonymous/1139167 to your computer and use it in GitHub Desktop.
Save anonymous/1139167 to your computer and use it in GitHub Desktop.
;; amalloy's solution to Number Maze
;; https://4clojure.com/problem/106
(let [paths (fn [[curr :as path]]
(for [op [* / +]
:let [next (op curr 2)]
:when (integer? next)]
(cons next path)))
bfs (fn [choices]
(mapcat paths choices))]
(fn [start end]
(let [goal (comp #{end} first)]
(->> [[start]]
(iterate bfs)
(map #(filter goal %))
(filter seq)
ffirst
count))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment