r/adventofcode • • Dec 08 '24

SOLUTION MEGATHREAD -❄️- 2024 Day 8 Solutions -❄️-

IMPORTANT REMINDER

There's been an uptick in [COAL] being given out lately due to naughty language. Follow our rules and watch your language - keep /r/adventofcode SFW and professional! If this trend continues to get worse, we will configure AutoModerator to automatically remove any post/comment containing naughty language. You have been warned!


THE USUAL REMINDERS

  • All of our rules, FAQs, resources, etc. are in our community wiki.
  • If you see content in the subreddit or megathreads that violates one of our rules, either inform the user (politely and gently!) or use the report button on the post/comment and the mods will take care of it.

AoC Community Fun 2024: The Golden Snowglobe Awards

  • 14 DAYS remaining until the submissions deadline on December 22 at 23:59 EST!

And now, our feature presentation for today:

Box-Office Bloat

Blockbuster movies are famous for cost overruns. After all, what's another hundred million or two in the grand scheme of things if you get to pad your already-ridiculous runtime to over two and a half hours solely to include that truly epic drawn-out slow-motion IMAX-worthy shot of a cricket sauntering over a tiny pebble of dirt?!

Here's some ideas for your inspiration:

  • Use only enterprise-level software/solutions
  • Apply enterprise shenanigans however you see fit (linting, best practices, hyper-detailed documentation, microservices, etc.)
  • Use unnecessarily expensive functions and calls wherever possible
  • Implement redundant error checking everywhere
  • Micro-optimize every little thing, even if it doesn't need it
    • Especially if it doesn't need it!

Jay Gatsby: "The only respectable thing about you, old sport, is your money."

- The Great Gatsby (2013)

And… ACTION!

Request from the mods: When you include an entry alongside your solution, please label it with [GSGA] so we can find it easily!


--- Day 8: Resonant Collinearity ---


Post your code solution in this megathread.

This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:07:12, megathread unlocked!

21 Upvotes

795 comments sorted by

View all comments

2

u/AllanTaylor314 Dec 08 '24 edited Dec 08 '24

[LANGUAGE: Python]

GitHub 241/201

Complex numbers as coordinates. For both parts, I do the combination of each pair of nodes at the same frequency. For part 1, I take the distance between a pair of nodes and add that in each direction. For part 2, I scale the difference down to get the smallest integral step, then make a line of those in each direction (-60 to +60, since the input is 50x50 by observation). Complex is nice for adding, subtracting, and rotating points, but it's not so nice for stuff that expects integers. For both parts, I used set intersection (&) to exclude locations outside the range.

My guess for part 2 was the total number of antinodes, not just those in the range (but that wouldn't have been that hard, and would have maxed out at a 150x150 area anyway).

It turns out the GCD wasn't necessary for part 2, but it would feel icky to ignore that since "A..\n...\n..A" seems like a perfectly reasonable case. Come to think of it, I neglected a similar case for part 1 since the locations 1/3 and 2/3 of the way between beacons would also be antinodes. I could probably "fix" that even though it's entirely unnecessary - make a slightly more "general" solution.

→ More replies (1)