Day 8: Resonant Collinearity
Megathread guidelines
- Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
- You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL
FAQ
- What is this?: Here is a post with a large amount of details: https://programming.dev/post/6637268
- Where do I participate?: https://adventofcode.com/
- Is there a leaderboard for the community?: We have a programming.dev leaderboard with the info on how to join in this post: https://programming.dev/post/6631465
27 Comments
CameronDev@programming.dev · 8 pts · 1y
Rust
For the first time, I can post my solution, because I actually solved it on the day :D Probably not the cleanest or optimal solution, but it does solve the problem.
Very long, looking forward to someone solving it in 5 lines of unicode :D
Rin@lemm.ee · 4 pts · 1y
VegOwOtenks@lemmy.world · 5 pts · 1y
Haskell
I overslept 26 minutes (AoC starts at 06:00 here) which upsets me more than it should.
I thought this one was going to be hard on performance or memory but it was surprisingly easy.
lwhjp@lemmy.sdf.org · 2 pts · 1y
D'oh. Computing antinodes in a single direction and permuting pairs is a much neater approach that what I did!
hades@lemm.ee · 4 pts · 1y
Quant@programming.dev · 4 pts · 1y
Uiua
Adapting the part one solution for part two took me longer than part one did today, but I didn't want to change much anymore.
I even got scolded by the interpreter to split the evaluating line onto multiple ones because it got too long.
Can't say it's pretty but it does it's job ^^'
Run with example input here
lwhjp@lemmy.sdf.org · 3 pts · 1y
Haskell
Not a very pretty solution today, I'm afraid.
VegOwOtenks@lemmy.world · 2 pts · 1y
Whaaat? It is possible to declare mutliple signatures on one line? π€―
Does that function (
.+.) add tuples/coordinates?lwhjp@lemmy.sdf.org · 2 pts · 1y
Yup, that's right! The function monad is a bit of a mind-bender, but
(join f) x == f x xis a useful thing to remember.VegOwOtenks@lemmy.world · 2 pts · 1y
This is so cool, it's going to replace the lambda in my function pipeline for calculating pairs.
lwhjp@lemmy.sdf.org · 1 pts · 1y
BTW, for more in-depth vector stuff I usually use the Linear package.
mykl@lemmy.world · 3 pts · 1y
Dart
This really does feel like a weekend break this year, maybe Eric and co have begun to realise that family time is more precious than work time :-)
janAkali@lemmy.one · 4 pts · 1y
Last year the difficulty was fluctuating from 0 to 100 each day.
This year all problems so far are suspiciously easy. Maybe the second half of the month will be extra hard?
mykl@lemmy.world · 4 pts · 1y
Maybe we've been good all year :-)
mykl@lemmy.world · 2 pts · 1y
Uiua
Getting closer to an elegant solution, but still a way to go...
How to read this
Try it live!
sjmulder@lemmy.sdf.org · 2 pts · 1y
C
Not hard but a little fiddly.
::: spoiler Code
:::
https://github.com/sjmulder/aoc/blob/master/2024/c/day08.c
TunaCowboy@lemmy.world · 2 pts · 1y
python
::: spoiler solution
:::
Karmmah@lemmy.world · 2 pts · 1y
Julia
I was surprised when my solution worked for part 2 since I thought you also had to include fractions of antenna distances, but apparently not.
::: spoiler Code
:::
LeixB@lemmy.world · 1 pts · 1y
Haskell
janAkali@lemmy.one · 1 pts · 1y
Nim
Overall really simple puzzle, but description is so confusing, that I mostly solved it based on example diagrams.
Edit: much shorter and faster one-pass solution. Runtime: 132 us
Codeberg repo
wer2@lemm.ee · 1 pts · 1y
Lisp
Could probably just write points right to the results instead of to an intermediate list, but it runs instantly, so my motivation to do so was low. ::: spoiler Code
:::
ace@lemmy.ananace.dev · 1 pts · 1y
And I of course misread and wasted a bunch of time debugging the second part, entirely missed the fact that antinodes occurred on top of the emanating antennae as well...
::: spoiler C#
:::
Rin@lemm.ee · 1 pts · 1y
the_beber@lemm.ee · 1 pts · 1y
Kotlin
A bit late to the party, but here's my solution. I don't know, if you even need to search for the smallest integer vector in the same direction in part 2, but I did it anyway.
::: spoiler Code:
:::
cabhan@discuss.tchncs.de · 1 pts · 1y
Rust
https://gitlab.com/bricka/advent-of-code-2024-rust/-/blob/main/src/days/day08.rs?ref_type=heads
Katzenmann@feddit.org · 1 pts · 1y
Rust
Pretty happy with my solution today. I took my time today as it was a bit of a slow day and did it in Rust instead of python. Having proper Vec2 types is very nice.
::: spoiler Tap for spoiler
:::
vole@lemmy.world · 1 pts · 1y
Raku
::: spoiler Solution
:::
Gobbel2000@programming.dev · 1 pts · 1y
Rust
Proper Point and Vector types made this pretty simple, part 2 was just a tiny change (basically
whileinstead ofif), but left with a lot of copy-pasted code.::: spoiler Solution
:::
also on github
cabhan@discuss.tchncs.de · 2 pts · 1y
I also did it in Rust, though mine is quite a bit more verbose than yours :). https://gitlab.com/bricka/advent-of-code-2024-rust/-/blob/main/src/days/day08.rs?ref_type=heads
Have you considered using a
HashSet<(usize, usize)>to store the visited locations instead of a 2d vector?Gobbel2000@programming.dev · 1 pts · 1y
I try to use
Vecs instead ofHashSets and maps whenever the key domain is reasonably small (just the grid in this case), simply because in the end direct memory access is a lot faster than always hashing values.But looking at this case again, it is certainly a lot easier to have just
antinodes.len()at the end instead of counting all true values. This datastructure is also not really performance-critical, so aHashSetis probably the cleaner choice here.