do 2017 day 5
This commit is contained in:
@@ -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))))
|
||||
Reference in New Issue
Block a user