You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
897 B
Clojure

(def input-map
(->> (slurp "./in")
(clojure.string/split-lines)
(mapv vec)
(mapv (partial mapv #(- (int %) 48)))
))
(defn compare-heights [a b]
(if (or (nil? a) (nil? b) (< a b)) 1 0))
(println
(apply +
(for [y (range 0 (count input-map))
x (range 0 (count (first input-map)))]
(let [height (get-in input-map [y x])]
(if
(= 4
(apply +
(map
(partial compare-heights height)
[
(get-in input-map [(dec y) x])
(get-in input-map [(inc y) x])
(get-in input-map [y (dec x)])
(get-in input-map [y (inc x)])
]
)
)
)
(inc height)
0
)
)
)
)
)