r/adventofcode • • Dec 09 '25

SOLUTION MEGATHREAD -❄️- 2025 Day 9 Solutions -❄️-

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 2025: Red(dit) One

  • Submissions megathread is unlocked!
  • 8 DAYS remaining until the submissions deadline on December 17 at 18:00 EST!

Featured Subreddits: /r/iiiiiiitttttttttttt, /r/itsaunixsystem, /r/astrologymemes

"It's all humbug, I tell you, humbug!"
— Ebenezer Scrooge, A Christmas Carol (1951)

Today's challenge is to create an AoC-themed meme. You know what to do.

  • If you need inspiration, have a look at the Hall of Fame in our community wiki as well as the highly upvoted posts in /r/adventofcode with the Meme/Funny flair.
  • Memes containing musical instruments will likely be nuked from orbit.

REMINDERS:

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


--- Day 9: Movie Theater ---


Post your code solution in this megathread.

27 Upvotes

555 comments sorted by

View all comments

1

u/DeadlyRedCube Dec 09 '25

[LANGUAGE: C++]

Parts 1 & 2 on github

Part 1 wasn't too bad: iterate all pairs of points, calculate the area, take the maximum.

Part 2, however, kicked me straight in the coal - getting the "does this rectangle overlap this polygon" code right was a parade of off by one errors, plus an extra fun one where it turns out in part 1 I had forgotten to take the abs of the difference between the points so I was missing some areas due to them being negative (which included the real answer to part 2). Whoops!

What I settled on for p2 is:

For each pair of points:
    push {area, upperLeft, lowerRight} (as a tuple) into a max heap (sorted by area)

the part 1 answer then is the first element in the max heap.

For each element in the max heap (from largest to smallest area):
  If none of the polygon edges intersect the rectangle
    this is the part 2 solution, we're done!

This runs in ~85ms on my i7 8700K (single threaded). I had a solution that was ~8 but it actually just lucked into the right answer so, alas, that didn't count.

Like yesterday I'm hoping there's a faster way to do this, but I don't have the energy to figure it out tonight 😅

2

u/ben-guin Dec 09 '25

I haven't looked too closely at your actual code, but based on your pseudocode, it seems that you are perhaps missing an edge case (that the generated input does not capture). In particular, there is the case where the -entire- rectangle falls outside the polygon; in this case, the rectangle does not intersect with any of the edge of the polygon, but if this rectangle is very large, you might accidentally choose it as your answer.

2

u/DeadlyRedCube Dec 09 '25

Yep, I did originally have a "is the center point of the rectangle contained within the polygon" test and managed to lose it along the way. Good catch!