Day 8 part 2
This commit is contained in:
parent
dc670cfe15
commit
6f13a6f281
2 changed files with 42 additions and 0 deletions
|
@ -39,4 +39,36 @@ fun main() {
|
|||
}
|
||||
|
||||
println("Part 1: ${antinodes.count()}")
|
||||
|
||||
antinodes.clear()
|
||||
|
||||
for (positions in antennasByFrequency.values) {
|
||||
for ((first, second) in pairs(positions)) {
|
||||
val dx = second.x - first.x
|
||||
val dy = second.y - first.y
|
||||
|
||||
var pos = first
|
||||
while (grid.inside(pos)) {
|
||||
antinodes.add(pos)
|
||||
pos = Grid.Coordinate(pos.x + dx, pos.y + dy)
|
||||
}
|
||||
|
||||
pos = first
|
||||
while (grid.inside(pos)) {
|
||||
antinodes.add(pos)
|
||||
pos = Grid.Coordinate(pos.x - dx, pos.y - dy)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
println("Part 2: ${antinodes.count()}")
|
||||
}
|
||||
|
||||
|
||||
fun <T> pairs(list: List<T>) = sequence {
|
||||
for (i in list.indices) {
|
||||
for (j in 0..<i) {
|
||||
yield(list[i] to list[j])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
10
2024/src/main/resources/day8-sample.txt
Normal file
10
2024/src/main/resources/day8-sample.txt
Normal file
|
@ -0,0 +1,10 @@
|
|||
T.........
|
||||
...T......
|
||||
.T........
|
||||
..........
|
||||
..........
|
||||
..........
|
||||
..........
|
||||
..........
|
||||
..........
|
||||
..........
|
Loading…
Add table
Reference in a new issue