renames
This commit is contained in:
parent
d2e6f920f3
commit
a2492b2b2a
@ -6,21 +6,21 @@
|
|||||||
(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 (->> (for [a input
|
(def largest-rects (->> (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-rects
|
||||||
last
|
last
|
||||||
(apply area))
|
(apply area))
|
||||||
|
|
||||||
(defn normalize [x] (min 1 (max -1 x)))
|
(defn normalize [x] (min 1 (max -1 x)))
|
||||||
(defn orientation
|
(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]]
|
[[ax ay] [bx by] [cx cy]]
|
||||||
(normalize (- (* (- by ay) (- cx bx))
|
(normalize (- (* (- by ay) (- cx bx))
|
||||||
(* (- bx ax) (- cy by)))))
|
(* (- bx ax) (- cy by)))))
|
||||||
@ -36,15 +36,16 @@
|
|||||||
(def line-segments (map vector input (rest input)))
|
(def line-segments (map vector input (rest input)))
|
||||||
|
|
||||||
;; part 2
|
;; part 2
|
||||||
(->> largest-squares
|
(->> largest-rects
|
||||||
(filter (fn [[a b]]
|
(filter (fn [[a b :as rect]]
|
||||||
(let [segments (filter (fn overlapping? [[seg-a seg-b]]
|
(let [segments (filter (fn overlapping? [[c d]]
|
||||||
(and (not= a seg-a) (not= a seg-b)
|
(and (not= a c) (not= a d)
|
||||||
(not= b seg-a) (not= b seg-b))) ;; filter out segments that include points a or b
|
(not= b c) (not= b d))) ;; filter out segments that include points a or b
|
||||||
line-segments)
|
line-segments)
|
||||||
[[cx cy] [dx dy]] [a b]]
|
[[cx cy] [dx dy]] rect
|
||||||
(and (not (some #(intersect? [a b] %) segments))
|
reverse-diag [[cx dy] [dx cy]]]
|
||||||
(not (some #(intersect? [[cx dy] [dx cy]] %) segments)))))) ;; check reverse diaganol too
|
(and (not (some #(intersect? rect %) segments))
|
||||||
|
(not (some #(intersect? reverse-diag %) segments))))))
|
||||||
(map (partial apply area))
|
(map (partial apply area))
|
||||||
sort
|
sort
|
||||||
last)
|
last)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user