<Advent of Code 2024 day 8> (spoilers) :thread:
# advent-of-code
a
a
Rank 441. Crazy how much difference it makes to get up at 05:45 instead of 06:45. Usually I'm at 2000+. My Coords helper class proved to be super useful as well.
This is part 2 only, for part 1 just set the multiple to 1. Too lazy to refactor.
m
Liked this one, my operator functions on points came in clutch today
👍 2
which reminds me, I need to make a 'product' utility function
m
Part 1
Part 2
👍 1
A library of grid utils was sure useful today.
n
Untitled
I was a little plodding today and kept getting bored and switching to lap Santa Barbara on The Last of Us. But it was another very basic one. One totally useless but kind of fun thing was I made an infix isWithin(grid) method for my Point class, so that I could
filter { antinode -> antinode isWithin cityLimits }
8.png
j
how come you didn't need gcd for part2? imagine antennas at (3,3) and (5,5). surely (4,4) should fit as well? so stepping by (2,2) wouldn't be correct. Or am I missing something
oooooooh no such case in input data. So I just wasted several minutes...
p
Yeah I thought about that too but then I took a look at the sample data and thought: Okay, whatever lets first try the easy route
s
Somehow the task today was very complex to understand, especially the second part. I'm still not sure I fully understand this sentence: "In fact, the three
T
-frequency antennas are all exactly in line with two antennas" With which two antennas? And how on Earth are three antennas in line with two if they aren't even in line with themselves?
same 2
m
It's "every antenna from the 3 antennas", not "all 3 antennas together" are in line.
T1 is in line with T1 and T2, T2 is in line with T2 and T3, and T3 is in line with T3 and T1.
p
@Sergei Petunin In line with the others
s
Thanks, that's a bit more clear now. I spent way too much time and LOC on this. I think my mistake was that I iterated over unique pairs of antennas and tried to calculate antinodes for every pair from both sides at once, and the code got crazy complicated fast. Looking at other solutions, it seems to be much easier to iterate over the pairs twice.
e
j
Nothing fancy today, except unnecessary after all GCD in part 2. Important part below, the rest on github
b
i didn't get to start on time but the hardest part was the wording of the question
👌 3
p
My sleep-addled brain spent too long trying to understand what the part2 text was telling me...
k
Pretty fun day. Day08.kt
a
I fully agree with @Sergei Petunin about the confusion on this one: > In fact, the three
T
-frequency antennas are all exactly in line with two antennas, so they are all also antinodes! what was a 5 minute change took me 30 mins to debug coz I thought my node generation was wrong. and all I needed to do was remove a
drop(1)
🤦
🧌 1
this explanation by @Marcin Wisniowski makes more sense than the puzzle description:
It's "every antenna from the 3 antennas", not "all 3 antennas together" are in line.
or rather: for T1 and T2, T2 is in line for T1 and T3, T3 is in line for T2 and T1, T1 is in line. etc. so any non-single antenna becomes and antinode. (my input didn't have any single nodes)
v
A solution concisely using Kotlin sequences for all traversals: https://github.com/vkopichenko/Contests/blob/main/adventofcode/src/2024/y24day8.kt
j
Not too difficult. Yesterday I decided to brush up on combinations and permutations, I think after the livestream, and it came in handy today. https://github.com/JBeet/MyAdventOfCode2024/blob/main/src/Day08.ipynb
a
conversely, I don't think that diagram is correct. it implies / shows that the 'T' antennas are in-line with antinodes - hence become antinodes themselves. but the criteria to create antinodes is being in line with other antennas (not antinodes).
anyway, I quite like how the final code for this looks. the only thing not here is
Point.minus(other: Point)
which is just like
plus
written in previous years. both parts use sequences, so the only diff is
getAntiNodes(drop = 1, take = 1)
vs
getAntiNodes(drop = 0, take = Int.MAX_VALUE)
(that large
take
doesn't matter since it's a sequence)
o
image.png
j
Finally, some visualization
🤩 5
👍 2
c
I found it a confusingly worded puzzle. In the end I settled on for part 1 "antinodes are created equal distances apart from each antenna pair" and for part 2 "that pattern repeats forever each side and also each antenna itself is also an antinode".
same 1
My code's a mess but I don't particularly care for that one. Didn't find it particularly interesting.
t
I spent a fair amount of time trying to figure out what was actually being asked for in Part 2. I left out the case where both antennas are on a vertical or horizontal line (my input didn't have any, I suspect yours didn't either). All in all, a nice way to spend a Sunday morning - solving an AoC puzzle and watching the final Formula 1 race of the year! • BlogCode
K 1
And once again I am terrible at predicting part 2. I was thinking it would be something like "Now find the safest neighborhood to live in, the one that is free from nefarious Easter Bunny mind control rays". But alas, the Easter Bunny continues his evil ways.
🐰 2
Not sure how others felt, but I definitely found problem statement very confusing, if it's talking about distance b/w antennas to antindoes or antenaas to antenaas considering distance and from the line, and use some mathy approach - euclidian distance <> line-equation. Definitely, didn't enjoy, coding this one.. it was more of what problem statement is trying to convey, rather than thinking of logic. It's a bit straightforward to code, after looking at just the pattern. Just looked at the pattern and brute-forced all the way.
@Jakub Gwóźdź what tool you used for visualisation.
j
@ritesh I'm ashamed to talk about it because I was in hurry... But it was Swing's JFrame 😆 https://github.com/jakubgwozdz/advent-of-code-2024/blob/main/aoc2024/src/main/kotlin/day8/Day8Video.kt
thank you color 1
🧑‍🎨 1
m
That's perfectly reasonable! What I liked to use for visualizations is just
BufferedImage
, saving every frame to a PNG and then converting the output PNGs to a video. Probably ends up simpler to just set pixel colors at coordinates, than dealing with UI.
j
Yeah, some time ago I was doing animgifs exactly that way, I just didn't wanted to re-learn all the apis and libraries needed for that 🙂
r
Thank you, i was getting my hands-on on k-notebook, and thought it added some animation and stuff.
j
So I used two threads here: one controlling the speed of computations and the second producing BufferedImage and displaying it on JPanel 🙂
👍 1
And recorded on mac using command-shift-5 :)
r
Here's my solutions in Kotlin Notebook kotlin notebook https://gist.github.com/belovrv/0bec0307b45a19e77e80f1c43ade3b9f
❤️ 1
d
Busy yesterday so I’m doing 2 today
Screenshot 2024-12-08 at 8.08.43 PM.png