do 2017 day 5

This commit is contained in:
2026-04-26 11:00:57 -04:00
parent 8ff632503f
commit 5077215205
+30
View File
@@ -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))))