Skip to content

Instantly share code, notes, and snippets.

@buntine
Last active December 8, 2023 23:45
Show Gist options
  • Save buntine/e91abf7f989337c4b10bc645f891c190 to your computer and use it in GitHub Desktop.
Save buntine/e91abf7f989337c4b10bc645f891c190 to your computer and use it in GitHub Desktop.
advent-of-code-2023-day8.clj
(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))
(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