|
|
@ -1,4 +1,4 @@
|
|
|
|
; Day 2, part 2
|
|
|
|
; Day 2, part 1
|
|
|
|
; Read a list of instructions from stdin:
|
|
|
|
; Read a list of instructions from stdin:
|
|
|
|
; "down X" increases depth number by X,
|
|
|
|
; "down X" increases depth number by X,
|
|
|
|
; "up X" decreases depth by X,
|
|
|
|
; "up X" decreases depth by X,
|
|
|
@ -8,24 +8,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
(require '[clojure.string :as str])
|
|
|
|
(require '[clojure.string :as str])
|
|
|
|
|
|
|
|
|
|
|
|
(loop [data {:xpos 0 :depth 0}]
|
|
|
|
(println
|
|
|
|
(let [input (read-line)]
|
|
|
|
(keduce *
|
|
|
|
(if (empty? input)
|
|
|
|
(vals
|
|
|
|
(println (apply * (vals data)))
|
|
|
|
(reduce
|
|
|
|
(let [ins (str/split input #" ")
|
|
|
|
#(case (first %2)
|
|
|
|
n (Integer/parseInt (second ins))
|
|
|
|
"forward" (update %1 :xpos + (second %2))
|
|
|
|
]
|
|
|
|
"up" (update %1 :depth - (second %2))
|
|
|
|
(recur
|
|
|
|
"down" (update %1 :depth + (second %2))
|
|
|
|
(apply (partial update-in data)
|
|
|
|
)
|
|
|
|
(case (first ins)
|
|
|
|
{:xpos 0 :depth 0}
|
|
|
|
"forward" [[:xpos] + n]
|
|
|
|
(->> (slurp "./in")
|
|
|
|
"up" [[:depth] - n]
|
|
|
|
str/split-lines
|
|
|
|
"down" [[:depth] + n]
|
|
|
|
(map #(str/split % #" "))
|
|
|
|
)
|
|
|
|
(map #(update % 1 read-string))
|
|
|
|
)
|
|
|
|
)))))
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|