golf
This commit is contained in:
parent
e0fba7c72f
commit
da7b893c37
@ -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 *))
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user