inline all the things

This commit is contained in:
Adam Jeniski 2023-12-03 10:19:03 -05:00
parent 1487d96ead
commit 7396fcc6d1

View File

@ -16,14 +16,6 @@
(mapcat identity) (mapcat identity)
(into {}))) (into {})))
(defn touches-symbol? [[row-idx col-idx s]]
(let [length (count s)]
(->> (for [r [(dec row-idx) row-idx (inc row-idx)]
c (range (dec col-idx) (+ col-idx length 1))]
(char-map [r c]))
(filter (comp not nil?))
(some #(not (or (Character/isDigit %) (= % \.)))))))
;; part 1 ;; part 1
(->> lines (->> lines
(map parse-nums) (map parse-nums)
@ -31,19 +23,16 @@
(map #(vector row (:start %) (:group %)) (map #(vector row (:start %) (:group %))
matches))) matches)))
(mapcat identity) (mapcat identity)
(filter touches-symbol?) (filter (fn touches-symbol? [[row-idx col-idx s]]
(let [length (count s)]
(->> (for [r [(dec row-idx) row-idx (inc row-idx)]
c (range (dec col-idx) (+ col-idx length 1))]
(char-map [r c]))
(filter (comp not nil?))
(some #(not (or (Character/isDigit %) (= % \.))))))))
(map #(Integer/parseInt (nth % 2))) (map #(Integer/parseInt (nth % 2)))
(reduce +)) (reduce +))
(defn touches-star? [[row-idx col-idx s]]
(let [length (count s)]
(->> (for [r [(dec row-idx) row-idx (inc row-idx)]
c (range (dec col-idx) (+ col-idx length 1))]
[[r c] (char-map [r c])])
(filter #(not (nil? (second %))))
(filter #(= \* (second %)))
(map #(vector % s)))))
;; part 2 ;; part 2
(let [data (->> lines (let [data (->> lines
(map parse-nums) (map parse-nums)
@ -51,7 +40,14 @@
(map #(vector row (:start %) (:group %)) (map #(vector row (:start %) (:group %))
matches))) matches)))
(mapcat identity) (mapcat identity)
(map touches-star?) (map (fn touching-star [[row-idx col-idx s]]
(let [length (count s)]
(->> (for [r [(dec row-idx) row-idx (inc row-idx)]
c (range (dec col-idx) (+ col-idx length 1))]
[[r c] (char-map [r c])])
(filter #(not (nil? (second %))))
(filter #(= \* (second %)))
(map #(vector % s))))))
(filter seq) (filter seq)
(mapcat identity) (mapcat identity)
(map #(vector (ffirst %) (second %)))) (map #(vector (ffirst %) (second %))))