mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-09-30 13:03:19 -09:00
format
This commit is contained in:
parent
34a17e5edb
commit
656d8bb725
@ -24,32 +24,33 @@
|
|||||||
matches)))
|
matches)))
|
||||||
(mapcat identity)))
|
(mapcat identity)))
|
||||||
|
|
||||||
|
(defn coords-to-check [row col num-str]
|
||||||
|
(for [r [(dec row) row (inc row)]
|
||||||
|
c (range (dec col) (+ col (count num-str) 1))]
|
||||||
|
[r c]))
|
||||||
|
|
||||||
;; part 1
|
;; part 1
|
||||||
(->> (parse-nums lines)
|
(->> (parse-nums lines)
|
||||||
(filter (fn touches-symbol? [[row-idx col-idx s]]
|
(filter (fn touches-symbol? [[row col s]]
|
||||||
(let [length (count s)]
|
(->> (coords-to-check row col s)
|
||||||
(->> (for [r [(dec row-idx) row-idx (inc row-idx)]
|
(map char-map)
|
||||||
c (range (dec col-idx) (+ col-idx length 1))]
|
|
||||||
(char-map [r c]))
|
|
||||||
(filter (comp not nil?))
|
(filter (comp not nil?))
|
||||||
(some #(not (or (Character/isDigit %) (= % \.))))))))
|
(some #(not (or (Character/isDigit %) (= % \.)))))))
|
||||||
(map #(Integer/parseInt (nth % 2)))
|
(map #(Integer/parseInt (nth % 2)))
|
||||||
(reduce +))
|
(reduce +))
|
||||||
|
|
||||||
;; stars is a list of [[star-row-idx star-col-idx] "num"]
|
;; stars is a list of [[star-row-idx star-col-idx] "num"]
|
||||||
;; stars is list of each * char found touching a number when iterating by nums
|
;; stars is list of each * char found touching a number when iterating by nums
|
||||||
(def stars (->> (parse-nums lines)
|
(def stars (->> (parse-nums lines)
|
||||||
(map (fn touching-stars [[row-idx col-idx s]]
|
(map (fn touching-stars [[row col s]]
|
||||||
(let [length (count s)]
|
(->> (coords-to-check row col s)
|
||||||
(->> (for [r [(dec row-idx) row-idx (inc row-idx)]
|
(map #(vector % (char-map %)))
|
||||||
c (range (dec col-idx) (+ col-idx length 1))]
|
|
||||||
[[r c] (char-map [r c])])
|
|
||||||
(filter #(not (nil? (second %))))
|
(filter #(not (nil? (second %))))
|
||||||
(filter #(= \* (second %)))
|
(filter #(= \* (second %)))
|
||||||
(map #(vector % s))))))
|
(map #(vector % s)))))
|
||||||
(filter seq)
|
(filter seq)
|
||||||
(mapcat identity)
|
(mapcat identity)
|
||||||
(map #(vector (ffirst %) (second %)))))
|
(map (fn [[[coords] num]] [coords num]))))
|
||||||
|
|
||||||
;; gears is a set of [star-row-idx star-col-idx]
|
;; gears is a set of [star-row-idx star-col-idx]
|
||||||
;; gears is a list of each * char that is touching exactly 2 nums
|
;; gears is a list of each * char that is touching exactly 2 nums
|
||||||
@ -67,6 +68,5 @@
|
|||||||
(map #(second (update % 1 (partial map second))))
|
(map #(second (update % 1 (partial map second))))
|
||||||
(map (partial map #(Integer/parseInt %)))
|
(map (partial map #(Integer/parseInt %)))
|
||||||
(map (partial reduce *))
|
(map (partial reduce *))
|
||||||
(reduce +)
|
(reduce +))
|
||||||
)
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user