init day 8

This commit is contained in:
Adam Jeniski 2024-12-08 00:58:18 -05:00
parent e9b4eabf3e
commit 8ac20241c9
3 changed files with 96 additions and 1 deletions

View File

@ -1,3 +1,4 @@
{:deps {org.clojure/clojure {:mvn/version "1.12.0"}}
{:deps {org.clojure/clojure {:mvn/version "1.12.0"}
org.clojure/math.combinatorics {:mvn/version "0.3.0"}}
:paths ["src"]
:tasks {}}

50
2024/input/8.txt Normal file
View File

@ -0,0 +1,50 @@
........5................r..................B.....
....................................V..B..........
...........................................B......
r..................C....................Y......N..
............................C.....................
vb.r........9......x..................7...........
..v........C.........................U...7.N..6...
5............9..................n.B...............
....r........4....................0.....K.....Y...
..4...C............7.......U..........6...........
......4z....................n.......U....6........
..............b...........N..........n............
.......9............x.....V..............K........
.....v......................................2.....
.....V........Z........n..........................
....z..........................VU......K..........
...b....z..............................Y..........
.z.......Z..................................K.....
..b.................................7.............
.4x...............................................
.h.......................5........................
.................................g................
..............9....0.........c................d...
......h.................u.............c........2.d
.....................8........N.....c...2.T.......
......Z..h.......................................c
........H........d................................
........................................d.........
.Z........................................k.......
...............................T...............6..
q..............Q...X..O............2..............
..............................O.8......D..........
........X............................O............
.........t......................T.................
..........................t...8.......Q......u....
.................Q.....O..........................
..........hj.......o..............JR....u.........
..........X..........ot.........3.R...............
.......J.............y.....3.....................g
............y..J.Xj......R..........G.............
.....................t.........H.....D..g...G.....
........J.......o......y.......k..................
..................1...............................
.....................3....k.......q.........1.....
...........v......................3k..............
...................1......Q...H............G......
.............1y......T............j...............
......0............8..................D........u..
.............................G....D...o....q......
...............j.0...H............................

44
2024/src/day08.clj Normal file
View File

@ -0,0 +1,44 @@
(ns day08
(:require
[core :as c]
[input-manager :refer [get-input]]
[clojure.math.combinatorics :as combo]
[clojure.set :refer [union]]))
(def input (mapv vec (get-input 8)))
(defn get-char [[row col]]
(get (get input row) col))
(def locs (->> input
c/get-coords
(map #(vector (get-char %) %))
(group-by first)
(#(dissoc % \.))
(#(update-vals % (partial mapv second)))))
(defn get-antinode-pos [[x1 y1] [x2 y2] multiplier]
(vector (+ x1 (* multiplier (- x2 x1)))
(+ y1 (+ (* multiplier (- y2 y1))))))
(defn get-antinodes [[a b]]
(filterv #(get-char %) [(get-antinode-pos a b 2) (get-antinode-pos b a 2)]))
;; part 1
(->> locs
vals
(map #(->> (combo/combinations % 2) (mapcat get-antinodes) set))
(reduce union)
(count))
(defn get-antinodes-2 [[a b]]
(concat (take-while get-char (map #(get-antinode-pos a b %) (range)))
(take-while get-char (map #(get-antinode-pos b a %) (range)))))
;; part 2
(->> locs
vals
(map #(->> (combo/combinations % 2) (mapcat get-antinodes-2) set))
(reduce union)
(count))