golf
This commit is contained in:
parent
63746d88b8
commit
ac6c0097e6
@ -3,33 +3,28 @@
|
|||||||
|
|
||||||
(def input (input-manager/get-input 2025 6))
|
(def input (input-manager/get-input 2025 6))
|
||||||
|
|
||||||
(def num-line? (comp not #{\* \+} first))
|
(def numeric-line? (comp not #{\* \+} first))
|
||||||
(def nums-raw (take-while num-line? input))
|
(def numeric-lines (take-while numeric-line? input))
|
||||||
(def nums (map (comp (partial map parse-long) #(re-seq #"\d+" %)) nums-raw))
|
(def nums (map #(map parse-long (re-seq #"\d+" %)) numeric-lines))
|
||||||
(def ops (->> input
|
(def ops (->> (drop-while numeric-line? input)
|
||||||
(drop-while num-line?)
|
first
|
||||||
(first)
|
|
||||||
(filter (partial not= \space))
|
(filter (partial not= \space))
|
||||||
(mapv {\+ +, \* *})))
|
(mapv {\+ +, \* *})))
|
||||||
|
|
||||||
;; part 1
|
;; part 1
|
||||||
(->> nums
|
(apply + (apply map (fn [op & rst] (apply op rst))
|
||||||
(apply map (fn [op & rst]
|
ops
|
||||||
(apply op rst))
|
nums))
|
||||||
ops)
|
|
||||||
(apply +))
|
|
||||||
|
|
||||||
;; part 2
|
;; part 2
|
||||||
(->> (range (count (first nums-raw)))
|
(->> (range (count (first numeric-lines)))
|
||||||
(reduce (fn [{:keys [op-idx curr-nums] :as acc} col-idx]
|
(reduce (fn [{:keys [op-idx curr-nums] :as acc} col-idx]
|
||||||
(let [op (get ops op-idx)
|
(let [op (ops op-idx)
|
||||||
col (->> nums-raw
|
col (->> (map #(.charAt % col-idx) numeric-lines)
|
||||||
(map #(.charAt % col-idx))
|
|
||||||
(filter (partial not= \space))
|
(filter (partial not= \space))
|
||||||
(map #(- (int %) (int \0))))]
|
(map #(- (int %) (int \0))))]
|
||||||
(if (empty? col)
|
(if (empty? col)
|
||||||
(-> acc
|
(-> (update acc :ans + (apply op curr-nums))
|
||||||
(update :ans + (apply op curr-nums))
|
|
||||||
(update :op-idx inc)
|
(update :op-idx inc)
|
||||||
(assoc :curr-nums []))
|
(assoc :curr-nums []))
|
||||||
(update acc :curr-nums conj (parse-long (apply str col))))))
|
(update acc :curr-nums conj (parse-long (apply str col))))))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user