From a2492b2b2adb6027a9dab72eb1eedeb77d198fd6 Mon Sep 17 00:00:00 2001 From: ajet Date: Tue, 9 Dec 2025 06:33:04 -1000 Subject: [PATCH] renames --- 2025/src/day09.clj | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/2025/src/day09.clj b/2025/src/day09.clj index ec988c4..70ca334 100644 --- a/2025/src/day09.clj +++ b/2025/src/day09.clj @@ -6,21 +6,21 @@ (defn area [[ax ay] [bx by]] (* (inc (abs (- ax bx))) (inc (abs (- ay by))))) -(def largest-squares (->> (for [a input - b input - :when (not= a b)] - #{a b}) - distinct - (map vec) - (sort-by #(apply area %)))) +(def largest-rects (->> (for [a input + b input + :when (not= a b)] + #{a b}) + distinct + (map vec) + (sort-by #(apply area %)))) ;; part 1 -(->> largest-squares +(->> largest-rects last (apply area)) (defn normalize [x] (min 1 (max -1 x))) (defn orientation - "returns a value indicating if point A is to the left, right, or on the line BC" + "returns a value indicating if point B is to the left, right, or on the line AC" [[ax ay] [bx by] [cx cy]] (normalize (- (* (- by ay) (- cx bx)) (* (- bx ax) (- cy by))))) @@ -36,15 +36,16 @@ (def line-segments (map vector input (rest input))) ;; part 2 -(->> largest-squares - (filter (fn [[a b]] - (let [segments (filter (fn overlapping? [[seg-a seg-b]] - (and (not= a seg-a) (not= a seg-b) - (not= b seg-a) (not= b seg-b))) ;; filter out segments that include points a or b +(->> largest-rects + (filter (fn [[a b :as rect]] + (let [segments (filter (fn overlapping? [[c d]] + (and (not= a c) (not= a d) + (not= b c) (not= b d))) ;; filter out segments that include points a or b line-segments) - [[cx cy] [dx dy]] [a b]] - (and (not (some #(intersect? [a b] %) segments)) - (not (some #(intersect? [[cx dy] [dx cy]] %) segments)))))) ;; check reverse diaganol too + [[cx cy] [dx dy]] rect + reverse-diag [[cx dy] [dx cy]]] + (and (not (some #(intersect? rect %) segments)) + (not (some #(intersect? reverse-diag %) segments)))))) (map (partial apply area)) sort last)