Created
December 5, 2017 19:01
-
-
Save osfameron/b3ec5d6628e27b98c671969073ae5a57 to your computer and use it in GitHub Desktop.
AoC day 5 sketch
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
(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