Skip to content

Instantly share code, notes, and snippets.

@osfameron
Created December 5, 2017 19:01
Show Gist options
  • Save osfameron/b3ec5d6628e27b98c671969073ae5a57 to your computer and use it in GitHub Desktop.
Save osfameron/b3ec5d6628e27b98c671969073ae5a57 to your computer and use it in GitHub Desktop.
AoC day 5 sketch
(require '[clojure.zip :as zip])
(def s '(0 3 0 1 -3))
(defn step [z]
(let [v (zip/node z)
dir (if (pos? v) zip/right zip/left)]
(->> z
(#(zip/edit % inc))
(iterate dir)
(take (inc (Math/abs v)))
last)))
(defn solve [s]
(->> s
zip/seq-zip
zip/down
(iterate step)
(take-while some?)
count))
(solve s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment