-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path2024-08-resonant-collinearity.clj
36 lines (33 loc) · 1.13 KB
/
2024-08-resonant-collinearity.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(defn parse [sz]
(let [point (fn [idx] [(mod idx sz) (quot idx sz)])]
(comp cat
(map-indexed vector)
(remove (comp #{\.} second))
(map (juxt second (comp point first))))))
(defn locations
([xs] xs)
([xs [k v]] (update xs k (fnil conj []) v)))
(defn solve [xs steps size]
(for [[ax ay] xs
[bx by] xs
step steps
:let [cx (+ ax (* step (- ax bx)))
cy (+ ay (* step (- ay by)))]
:while (and (not= ax bx)
(not= ay by)
(>= cx 0)
(>= cy 0)
(< cx size)
(< cy size))]
(+ cx (* cy size))))
(let [in (line-seq (java.io.BufferedReader. *in*))
sz (count in)
xs (transduce (parse sz) locations {} in)
xf (fn [steps]
(comp (remove (comp #{\.} key))
(filter (comp (fn [x] (> x 1)) count val))
(mapcat (fn [[_ xs]] (solve xs steps sz)))
(distinct)
(map (constantly 1))))]
(println "Part A:" (transduce (xf (list 1)) + xs))
(println "Part B:" (transduce (xf (range sz)) + xs)))