From da7b893c37951e6ba1e53ef23e5d377390bf82e3 Mon Sep 17 00:00:00 2001 From: ajet Date: Mon, 8 Dec 2025 14:00:26 -1000 Subject: [PATCH] golf --- 2025/src/day08.clj | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/2025/src/day08.clj b/2025/src/day08.clj index 296f594..e74c935 100644 --- a/2025/src/day08.clj +++ b/2025/src/day08.clj @@ -11,17 +11,17 @@ (+ (square (- ax bx)) (square (- ay by)) (square (- az bz)))) -(def closest-points - (->> (for [a input - b input - :when (not= a b)] - #{a b}) - distinct - (map vec) - (sort-by (partial apply dist-squared)))) +(def closest-points (->> (for [a input + b input + :when (not= a b)] + #{a b}) + distinct + (map vec) + (sort-by (partial apply dist-squared)))) +;; part 1 (->> closest-points - (take (count input)) + (take 1000) (reduce (fn [circuits [a b]] (let [circuit-a (first (filter #(% a) circuits)) circuit-b (first (filter #(% b) circuits))] @@ -38,20 +38,19 @@ (map count) (apply *)) -(->> (loop [circuits circuits - [[a b] & rst] (take 10000 closest-points)] - (let [circuit-a (first (filter #(% a) circuits)) - circuit-b (first (filter #(% b) circuits))] - (if (= circuit-a circuit-b) - (recur circuits rst) - (let [combined (clojure.set/union circuit-a circuit-b) - circuits' (-> circuits - (disj circuit-a) - (disj circuit-b) - (conj combined))] - (if (= 1 (count circuits')) - [a b] - (recur circuits' rst)))))) +;; part 2 +(->> (take 6498 closest-points) + (reduce (fn [circuits [a b]] + (let [circuit-a (first (filter #(% a) circuits)) + circuit-b (first (filter #(% b) circuits))] + (if (= circuit-a circuit-b) + circuits + (let [combined (clojure.set/union circuit-a circuit-b) + circuits' (-> circuits (disj circuit-a) (disj circuit-b) (conj combined))] + (if (= 1 (count circuits')) + (reduced [a b]) + circuits'))))) + circuits) (map first) (apply *))