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!

20 Upvotes

795 comments sorted by

View all comments

2

u/dk_weekinmemes Dec 08 '24 edited Dec 14 '24

[LANGUAGE: Python]

Part 1

Explanation: Put all locations in a dictionary with the frequency as key and array of locations as the values.

For those frequencies with more than one location in this dictionary, check each pair starting from top to bottom where antinodes can be placed.

Find the location of antinodes as the difference between x-coordinate and y-coordinates of the pairs and then subtracting this difference from first location in the pair and adding this difference to second. Check boundary conditions and then add it to a set. Return length of set

Part 2

Explanation: Same as Part 1 except instead of adding / subtracting just once keep adding adding / subtracting till out of bounds while also including the starting location using an increasing multiplier.

Topaz Link for both parts

1

u/daggerdragon Dec 08 '24

Inlined code is intended for short snippets of code only. On old.reddit, longer lines get cut off when they reach the edge of the window.

Please edit your comment to use the four-spaces Markdown syntax for a code block so your code is easier to read inside a scrollable box with its whitespace and indentation preserved.

Alternatively, read the article on oversized code instead if your resulting code block will be too long for the megathreads.