Last active
December 8, 2023 23:45
-
-
Save buntine/e91abf7f989337c4b10bc645f891c190 to your computer and use it in GitHub Desktop.
advent-of-code-2023-day8.clj
This file contains 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
(defn path-follower [[dir & rest-dirs] graph edge] | |
(let [next-edge ((edge graph) ({:L 0 :R 1} dir))] | |
(->> (path-follower rest-dirs graph next-edge) | |
(cons edge) | |
lazy-seq))) | |
(defn steps [path graph start-edge goal] | |
(->> (path-follower (cycle path) graph start-edge) | |
(take-while #(not= % goal)) | |
count)) |
This file contains 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
(defn path-follower [path-seq graph edge] | |
(let [dir (first path-seq) | |
next-edge ((edge graph) ({:L 0 :R 1} dir))] | |
(lazy-seq | |
(cons position | |
(path-follower (drop 1 path-seq) graph next-edge))))) | |
(defn steps [path graph start-edge goal] | |
(count | |
(take-while #(not= % goal) | |
(path-follower (cycle path) graph start-edge)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment