1 | ||
1 | ||
1 | ||
1 |
--- Day 8: Resonant Collinearity ---
You find yourselves on the roof of a top-secret Easter Bunny installation.
While The Historians do their thing, you take a look at the familiar huge antenna. Much to your surprise, it seems to have been reconfigured to emit a signal that makes people 0.1% more likely to buy Easter Bunny brand Imitation Mediocre Chocolate as a Christmas gift! Unthinkable!
Scanning across the city, you find that there are actually many such antennas. Each antenna is tuned to a specific frequency indicated by a single lowercase letter, uppercase letter, or digit. You create a map (your puzzle input) of these antennas. For example:
............
........0...
.....0......
.......0....
....0.......
......A.....
............
............
........A...
.........A..
............
............
The signal only applies its nefarious effect at specific antinodes based on the resonant frequencies of the antennas. In particular, an antinode occurs at any point that is perfectly in line with two antennas of the same frequency - but only when one of the antennas is twice as far away as the other. This means that for any pair of antennas with the same frequency, there are two antinodes, one on either side of them.
So, for these two antennas with frequency a, they create the two antinodes marked with #:
..........
...#......
..........
....a.....
..........
.....a....
..........
......#...
..........
..........
Adding a third antenna with the same frequency creates several more antinodes. It would ideally add four antinodes, but two are off the right side of the map, so instead it adds only two:
..........
...#......
#.........
....a.....
........a.
.....a....
..#.......
......#...
..........
..........
Antennas with different frequencies don't create antinodes; A and a count as different frequencies. However, antinodes can occur at locations that contain antennas. In this diagram, the lone antenna with frequency capital A creates no antinodes but has a lowercase-a-frequency antinode at its location:
..........
...#......
#.........
....a.....
........a.
.....a....
..#.......
......A...
..........
..........
The first example has antennas with two different frequencies, so the antinodes they create look like this, plus an antinode overlapping the topmost A-frequency antenna:
......#....#
...#....0...
....#0....#.
..#....0....
....0....#..
.#....A.....
...#........
#......#....
........A...
.........A..
..........#.
..........#.
Because the topmost A-frequency antenna overlaps with a 0-frequency antinode, there are 14 total unique locations that contain an antinode within the bounds of the map.
Calculate the impact of the signal. How many unique locations within the bounds of the map contain an antinode?
Input:
............
........0...
.....0......
.......0....
....0.......
......A.....
............
............
........A...
.........A..
............
............
Output: https://files.catbox.moe/wbdbb4.png
Solution: https://files.catbox.moe/r1plgf.png
What I learned: NOTHING! Once again, out of the box chat GPT solution, however, i had to use the o1 model (approved by the 05 counsel of SCP). So for some weird reason, i dunno why, my input has lines whose lengths dont match. So this will force that by adding more "." when it finds a line that isn't as long as other lines. Obviously i should put in something to cull longer lines then intended, but at that point im developing solutions and not solving problems (there is a difference). This is repacked into a 2d array. we then grab all locations as a vec2Int list, which is a just a list of vector 2's rounded to ints. We store these antenna positions grouped by their frequency character (for example, 'a' or '0'). If we haven't encountered this particular frequency before, we create a new entry for it in antennasByFreq. We iterate through each frequency group. For that frequency, we grab all antenna positions. We form pairs of antennas (A, B). For every pair, we use the formula C1 = 2A - B and C2 = 2B - A to find their potential antinode positions (thank you GPT). These formulas find points on the line defined by A and B that are twice as far from one antenna as they are from the other, which matches the antinode definition given in the puzzle. We then check if these computed points C1 and C2 fall within the grid boundaries. If they do, we add them to the antinodes set. Using a HashSet<Vector2Int> ensures that we only store unique antinode positions once, even if multiple antenna pairs produce the same antinode location.