Compare commits
2 Commits
940135c14c
...
d853e89137
| Author | SHA1 | Date | |
|---|---|---|---|
| d853e89137 | |||
| 0093533054 |
46
2025/src/day06.clj
Normal file
46
2025/src/day06.clj
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
(ns day06
|
||||||
|
(:require input-manager))
|
||||||
|
|
||||||
|
(def input
|
||||||
|
(input-manager/get-input 2025 6))
|
||||||
|
|
||||||
|
(def num-line? (comp not #{\* \+} first))
|
||||||
|
(def nums-raw (take-while num-line? input))
|
||||||
|
(def nums (->> nums-raw
|
||||||
|
(map #(map parse-long (re-seq #"\d+" %)))))
|
||||||
|
(def op-map {\+ +, \* *})
|
||||||
|
(def ops (as-> input v
|
||||||
|
(drop-while num-line? v)
|
||||||
|
(first v)
|
||||||
|
(filter (partial not= \space) v)
|
||||||
|
(mapv op-map v)))
|
||||||
|
|
||||||
|
;; part 1
|
||||||
|
(->> nums
|
||||||
|
(apply map (fn [op & rst]
|
||||||
|
(apply op rst))
|
||||||
|
ops)
|
||||||
|
(apply +))
|
||||||
|
|
||||||
|
;; part 2
|
||||||
|
(def MAX_LINE_IDX (dec (count (first nums-raw))))
|
||||||
|
(loop [col-idx 0
|
||||||
|
op-idx 0
|
||||||
|
curr-nums []
|
||||||
|
acc 0]
|
||||||
|
(if (> col-idx MAX_LINE_IDX)
|
||||||
|
(+ acc (apply (get ops op-idx) curr-nums))
|
||||||
|
(let [col (->> nums-raw
|
||||||
|
(map #(.charAt % col-idx))
|
||||||
|
(filter (partial not= \space))
|
||||||
|
(map #(- (int %) (int \0))))
|
||||||
|
op (get ops op-idx)]
|
||||||
|
(if (empty? col)
|
||||||
|
(recur (inc col-idx)
|
||||||
|
(inc op-idx)
|
||||||
|
[]
|
||||||
|
(+ acc (apply op curr-nums)))
|
||||||
|
(recur (inc col-idx)
|
||||||
|
op-idx
|
||||||
|
(conj curr-nums (parse-long (apply str col)))
|
||||||
|
acc)))))
|
||||||
Loading…
x
Reference in New Issue
Block a user