diff --git a/2017/src/day05.clj b/2017/src/day05.clj new file mode 100644 index 0000000..a5b8f30 --- /dev/null +++ b/2017/src/day05.clj @@ -0,0 +1,30 @@ +(ns day05 + (:require input-manager)) + +(def input (->> (input-manager/get-input 2017 5) + (mapv parse-long))) + +(def MAX_IDX (count input)) + +;; part 1 +(loop [steps 0 + maze input + idx 0] + (let [maze' (update maze idx inc) + idx' (+ (maze idx) idx)] + (if (< -1 idx' MAX_IDX) + (recur (inc steps) maze' idx') + (inc steps)))) + +;; part 2 +(loop [steps 0 + maze input + idx 0] + (let [offset (maze idx) + maze' (update maze idx (if (>= offset 3) + dec + inc)) + idx' (+ offset idx)] + (if (< -1 idx' MAX_IDX) + (recur (inc steps) maze' idx') + (inc steps))))