diff --git a/deps.edn b/deps.edn index aa775c4..a57e713 100644 --- a/deps.edn +++ b/deps.edn @@ -1,3 +1,4 @@ {:paths ["src" "cookies"] :deps {org.clojure/clojure {:mvn/version "1.12.0"} - clj-http/clj-http {:mvn/version "3.13.0"}}} + clj-http/clj-http {:mvn/version "3.13.0"} + org.clojure/math.combinatorics {:mvn/version "0.3.0"}}} diff --git a/src/day10.clj b/src/day10.clj new file mode 100644 index 0000000..655cc45 --- /dev/null +++ b/src/day10.clj @@ -0,0 +1 @@ +(ns day10) diff --git a/src/day8.clj b/src/day8.clj new file mode 100644 index 0000000..d39c628 --- /dev/null +++ b/src/day8.clj @@ -0,0 +1,66 @@ +(ns day8 + (:require [mapped-area] + [helpers :refer [get-input]] + [clojure.math.combinatorics :refer [combinations]])) + +(def test-city +"............ +........0... +.....0...... +.......0.... +....0....... +......A..... +............ +............ +........A... +.........A.. +............ +............") + +(def test-city2 +".......... +.......... +.......... +....a..... +........a. +.....a.... +.......... +.......... +.......... +..........") + +(def input + (-> + test-city + ;;(get-input 8) + mapped-area/read-mapped-area)) + +(defn antinodes [a [[x1 y1] [x2 y2]]] + (let [xd (abs (- x1 x2)) + yd (abs (- y1 y2)) + a1 [(+ (max x1 x2) xd) + (+ (max y1 y2) yd)] + a2 [(- (min x1 x2) xd) + (- (min y1 y2) yd)]] + (filter (partial mapped-area/mapped? a) [a1 a2]))) + +(defn antennas [a] + (reduce + (fn [m [coord value]] + (if (= value \.) + m + (update m value #(conj % coord)))) + {} + (mapped-area/mapped-area-indexed-seq a))) + +(defn antenna-pairs [a] + (mapcat (fn [[_ a]] (combinations a 2)) (antennas a))) + +(defn find-antinodes [m] + (let [a (mapped-area/read-mapped-area m)] + (->> (antenna-pairs a) + (mapcat #(antinodes a (vec %)))))) + +(def r (find-antinodes test-city2)) +(println r) +(println (set r)) diff --git a/src/mapped_area.clj b/src/mapped_area.clj index 2efeb19..49bb087 100644 --- a/src/mapped_area.clj +++ b/src/mapped_area.clj @@ -71,3 +71,8 @@ ijkl") (test #'h) (test #'w) (test #'mapped?) + +(defn mapped-area-indexed-seq [a] + (for [x (range (w a)) + y (range (h a))] + (vector [x y] (get-in a [x y]))))