-
Notifications
You must be signed in to change notification settings - Fork 0
/
day08.clj
22 lines (18 loc) · 888 Bytes
/
day08.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
(ns advent-2024-clojure.day08
(:require [abyala.advent-utils-clojure.core :as c]
[abyala.advent-utils-clojure.point :as p]))
(defn antinodes-beside [points [ant1 ant2]]
(filter points [(p/move ant2 (p/coord-distance ant1 ant2))
(p/move ant1 (p/coord-distance ant2 ant1))]))
(defn antinodes-in-line [points [ant1 ant2]]
(into (take-while points (iterate #(p/move % (p/coord-distance ant1 ant2)) ant2))
(take-while points (iterate #(p/move % (p/coord-distance ant2 ant1)) ant1))))
(defn solve [f input]
(let [points (p/parse-to-char-coords-map input)]
(->> (dissoc (group-by second points) \.)
(mapcat (comp c/unique-combinations (partial map first) second))
(mapcat (partial f points))
set
count)))
(defn part1 [input] (solve antinodes-beside input))
(defn part2 [input] (solve antinodes-in-line input))