Created
August 11, 2011 08:31
-
-
Save anonymous/1139167 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
;; 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