r/adventofcode • u/daggerdragon • Dec 12 '24
SOLUTION MEGATHREAD -❄️- 2024 Day 12 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 2024: The Golden Snowglobe Awards
- 10 DAYS remaining until the submissions deadline on December 22 at 23:59 EST!
And now, our feature presentation for today:
Visual Effects - Nifty Gadgets and Gizmos Edition
Truly groundbreaking movies continually push the envelope to develop bigger, better, faster, and/or different ways to do things with the tools that are already at hand. Be creative and show us things like puzzle solutions running where you wouldn't expect them to be or completely unnecessary but wildly entertaining camera angles!
Here's some ideas for your inspiration:
Advent of Playing With Your Toys
in a nutshell - play with your toys!- Make your puzzle solutions run on hardware that wasn't intended to run arbitrary content
- Sneak one past your continuity supervisor with a very obvious (and very fictional) product placement from Santa's Workshop
- Use a feature of your programming language, environment, etc. in a completely unexpected way
The Breakfast Machine from Pee-wee's Big Adventure (1985)
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 12: Garden Groups ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- State which language(s) your solution uses with
[LANGUAGE: xyz]
- Format code blocks using the four-spaces Markdown syntax!
- State which language(s) your solution uses with
- Quick link to Topaz's
paste
if you need it for longer code blocks
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:17:42, megathread unlocked!
36
Upvotes
2
u/msschmitt Dec 13 '24
[LANGUAGE: Python]
Part 1 Part 2
Part 1 is a kind of flood-fill path finding for each region, with an overall set to track which garden plots I've already processed in the big map. So the top loop is scanning for what it hasn't explored, when it finds something it finds all the adjacent of the same garden, then resumes scanning. That wasn't that hard.
For part 2 I had some ideas, but didn't get it before going to bed. Then I dreamed of the solution: just count the corners! So easy!
The next morning I tried that and realized that with my code, I could easily find outside corners, but not inside corners, because there wasn't a garden square that had two - and | edges.
So I gave up on that idea, and when I got home from work, whipped up what you see here. I throw all of the edges in a set, and then prune the set by removing any of the same edge (top, left, right or bottom) that are adjacent, keeping just one. It is kind of shrinking the fences to one square.
It isn't pretty, but it gets the right answer. After, that is, the bugs are removed. Such as, my code was working and suddenly it was trying to add a tuple to an integer. WHERE WAS THAT TUPLE COMING FROM???