|
|
@ -8,26 +8,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
(require '[clojure.string :as str])
|
|
|
|
(require '[clojure.string :as str])
|
|
|
|
|
|
|
|
|
|
|
|
(loop [xpos 0 depth 0 aim 0]
|
|
|
|
(loop [data {:xpos 0 :depth 0 :aim 0}]
|
|
|
|
(let [input (read-line)]
|
|
|
|
(let [input (read-line)]
|
|
|
|
(if (empty? input)
|
|
|
|
(if (empty? input)
|
|
|
|
(println (* xpos depth))
|
|
|
|
(println (apply * (map data [:xpos :depth])))
|
|
|
|
(let [ins (str/split input #" ")
|
|
|
|
(let [ins (str/split input #" ")
|
|
|
|
n (Integer/parseInt (second ins))
|
|
|
|
n (Integer/parseInt (second ins))
|
|
|
|
]
|
|
|
|
]
|
|
|
|
(recur
|
|
|
|
(recur
|
|
|
|
(if (= (first ins) "forward")
|
|
|
|
|
|
|
|
(+ xpos n)
|
|
|
|
|
|
|
|
xpos
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
(if (= (first ins) "forward")
|
|
|
|
|
|
|
|
(+ depth (* aim n))
|
|
|
|
|
|
|
|
depth
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
(case (first ins)
|
|
|
|
(case (first ins)
|
|
|
|
"down" (+ aim n)
|
|
|
|
"forward" (-> data
|
|
|
|
"up" (- aim n)
|
|
|
|
(update-in [:xpos] + n)
|
|
|
|
aim)
|
|
|
|
(update-in [:depth] + (* (data :aim) n))
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
"up" (update-in data [:aim] - n)
|
|
|
|
|
|
|
|
"down" (update-in data [:aim] + n)
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|