From 7ace3b811982a1f18a48152aa50ebced8a083560 Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Sun, 8 Dec 2024 19:33:27 +0100 Subject: [PATCH] Day 8 part 1 --- 2024/src/main/kotlin/day8.kt | 42 +++++++++++++++++++++++++++ 2024/src/main/resources/day8.txt | 50 ++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 2024/src/main/kotlin/day8.kt create mode 100644 2024/src/main/resources/day8.txt diff --git a/2024/src/main/kotlin/day8.kt b/2024/src/main/kotlin/day8.kt new file mode 100644 index 0000000..17e7834 --- /dev/null +++ b/2024/src/main/kotlin/day8.kt @@ -0,0 +1,42 @@ +fun main() { + val grid = Grid.read("day8.txt") + + val antennasByFrequency = mutableMapOf>() + for (y in 0..) = + antennas.any { antenna -> + val dx = antenna.x - coordinate.x + val dy = antenna.y - coordinate.y + val secondAntenna = Grid.Coordinate(antenna.x + dx, antenna.y + dy) + + secondAntenna != antenna && grid.inside(secondAntenna) && grid.get(secondAntenna) == frequency + } + + fun isAntinode(coordinate: Grid.Coordinate) = + antennasByFrequency.any { (frequency, positions) -> + isAntinode(coordinate, frequency, positions) + } + + val antinodes = mutableSetOf() + + for (y in 0..