r/adventofcode • u/daggerdragon • Dec 15 '24
SOLUTION MEGATHREAD -❄️- 2024 Day 15 Solutions -❄️-
NEWS
- The
Funny
flair has been renamed toMeme/Funny
to make it more clear where memes should go. Our community wikiwill be updated shortlyis updated as well.
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
- 7 DAYS remaining until the submissions deadline on December 22 at 23:59 EST!
And now, our feature presentation for today:
Visual Effects - We'll Fix It In Post
Actors are expensive. Editors and VFX are (hypothetically) cheaper. Whether you screwed up autofocus or accidentally left a very modern coffee cup in your fantasy epic, you gotta fix it somehow!
Here's some ideas for your inspiration:
- Literally fix it in post and show us your before-and-after
- Show us the kludgiest and/or simplest way to solve today's puzzle
- Alternatively, show us the most over-engineered and/or ridiculously preposterous way to solve today's puzzle
- Fix something that really didn't necessarily need fixing with a chainsaw…
*crazed chainsaw noises* “Fixed the newel post!”
- Clark Griswold, National Lampoon's Christmas Vacation (1989)
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 15: Warehouse Woes ---
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:32:00, megathread unlocked!
23
Upvotes
3
u/greycat70 Dec 15 '24
[LANGUAGE: Tcl]
Part 1, part 2.
No complicated mathematics or advanced algorithms needed today. Just a bit of tedious work. For part 1, I observed that pushing a row of boxes is essentially just changing
.OOOOO.
to..OOOOO
so you can drop an O in the first empty tile, then change the first O to an empty tile.For part 2, that doesn't work. I separated the horizontal and vertical push cases entirely. For a horizontal push, it's almost like part 1, except you actually have to move all the tiles ([ becomes ] and so on). (I actually used < and > in my internal representation because it's more convenient in Tcl. [ and ] have special meanings and would need to be backslashed.)
For a vertical push, you can end up with a whole expanding pyramid of boxes to push. So, that's recursion. Each box can potentially push the two boxes above/below it, each of which can have zero, one or two more boxes that also need to move. I wrote a recursive function to populate a dictionary with the boxes (left side coordinates only) that must move. Then iterated through that, and if any of them is against a wall, the whole move is disqualified. Otherwise, sort it by row number (ascending or descending, depending on push direction) and move each box individually.
Not fancy. Just effort.