golf
This commit is contained in:
parent
055a37a089
commit
c47c11a973
@ -3,19 +3,16 @@
|
|||||||
|
|
||||||
(def input (->> (input-manager/get-input 2025 9)
|
(def input (->> (input-manager/get-input 2025 9)
|
||||||
(mapv #(mapv parse-long (re-seq #"\d+" %)))))
|
(mapv #(mapv parse-long (re-seq #"\d+" %)))))
|
||||||
|
|
||||||
(defn area [[ax ay] [bx by]]
|
(defn area [[ax ay] [bx by]]
|
||||||
(* (inc (abs (- ax bx)))
|
(* (inc (abs (- ax bx)))
|
||||||
(inc (abs (- ay by)))))
|
(inc (abs (- ay by)))))
|
||||||
(def largest-squares
|
(def largest-squares (->> (for [a input
|
||||||
(->> (for [a input
|
b input
|
||||||
b input
|
:when (not= a b)]
|
||||||
:when (not= a b)]
|
#{a b})
|
||||||
#{a b})
|
distinct
|
||||||
distinct
|
(map vec)
|
||||||
(map vec)
|
(sort-by #(apply area %))))
|
||||||
(sort-by #(apply area %))))
|
|
||||||
|
|
||||||
;; part 1
|
;; part 1
|
||||||
(->> largest-squares
|
(->> largest-squares
|
||||||
last
|
last
|
||||||
@ -27,7 +24,6 @@
|
|||||||
[[ax ay] [bx by] [cx cy]]
|
[[ax ay] [bx by] [cx cy]]
|
||||||
(normalize (- (* (- by ay) (- cx bx))
|
(normalize (- (* (- by ay) (- cx bx))
|
||||||
(* (- bx ax) (- cy by)))))
|
(* (- bx ax) (- cy by)))))
|
||||||
|
|
||||||
(defn intersect?
|
(defn intersect?
|
||||||
"Lines AB and CD intersect if points A and B falls on different sides of CD
|
"Lines AB and CD intersect if points A and B falls on different sides of CD
|
||||||
and if C and D fall on different sides of AB"
|
and if C and D fall on different sides of AB"
|
||||||
@ -37,9 +33,9 @@
|
|||||||
o3 (orientation c d a)
|
o3 (orientation c d a)
|
||||||
o4 (orientation c d b)]
|
o4 (orientation c d b)]
|
||||||
(and (not= o1 o2) (not= o3 o4))))
|
(and (not= o1 o2) (not= o3 o4))))
|
||||||
|
(def line-segments (map vector input (conj (vec (rest input)) (first input))))
|
||||||
|
|
||||||
;; part 2
|
;; part 2
|
||||||
(def line-segments (map vector input (conj (vec (rest input)) (first input))))
|
|
||||||
(->> largest-squares
|
(->> largest-squares
|
||||||
(filter (fn [[a b]]
|
(filter (fn [[a b]]
|
||||||
(let [segments (filter (fn [[seg-a seg-b]] (and (not= a seg-a)
|
(let [segments (filter (fn [[seg-a seg-b]] (and (not= a seg-a)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user