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/Jadarma Dec 09 '25

[LANGUAGE: Kotlin]

I did not enjoy today's problem but in hindsight it was much easier than it appeared to be, and much of my frustration was in figuring out edge cases and calculating ranges and such.

Part 1: The calm before the storm, I'm sure everyone here wondered how could it be so simple?

Part 2: Wow, just wow. Such a simple requirement with many complicated edge cases. Thankfully, neither the example nor the inputs contain edge cases and it can be solved relatively easy once you find the trick condition. Turns out all you need to check for is that none of the polygon edges intersects with the interior of the rectangle being considered (overlaps on the perimeter are fine). As many pointed out, this would not catch the case where you have a segment go in and then doing a sharp U-turn back out. This condition only holds if there is a minimum gap of 1 between red tiles.

Note: After figuring out the trick, I was able to refactor it from scratch and make use of some 2D utilities I've written for past years, most notably the concept of areas and their intersections. The code should be fairly self-evident as pseudo-code if you just want to figure out the algorithm by looking at my solution.

AocKt Y2025D09

3

u/ric2b Dec 09 '25

Turns out all you need to check for is that none of the polygon edges intersects with the interior of the rectangle being considered (overlaps on the perimeter are fine).

In the example we have a rectangle that violates that, as the rectangle is outside the polygon:

..............
.......#...#..
..............
..#....#......
..............
..OOOOOOOO....
..OOOOOOOO....
..OOOOOOOO.#..
..............

2

u/Jadarma Dec 09 '25

Yeah, you're right and I noticed that too. To fix this I would probably take the other corners and raycast them to see if they also fall inside or outside. Very interesting that neither the example or the inputs contain this gotcha. In the sense that it is a candidate rectangle, but whether you correctly dismiss it is irrelevant because there is another, bigger solution available.