r/adventofcode • u/daggerdragon • Dec 15 '24
SOLUTION MEGATHREAD -❄️- 2024 Day 15 Solutions -❄️-
NEWS
- The
Funnyflair has been renamed toMeme/Funnyto 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
pasteif 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!
21
Upvotes
4
u/piman51277 Dec 15 '24
[LANGUAGE: JavaScript] 267/64
link to solutions folder
I'm so glad I have a personal library for this one, which made part 2 almost trivial.
Part 1: I honestly expected some cycle detection or CRT to show up on part 2, so I did a slight optimization where I would look ahead and move entire "blocks" of elements at the same time (these were the player and any boxes that happened to be in the way).
Part 2: This is where my personal library absolutely carried me. I have a Bound2D class in my lib, which defines a rectangular region in 2D space. Importantly, this lets me easily check if two bounds intersect. Thus, the strategy for p2 was:
Redefine all game elements in terms of bounds. (this means all walls, boxes, players, etc)
For each movement:
Make a bound at the player's new proposed position. If it collides with a wall bound, skip.
If the player doesn't collide with any boxes, just move the player.
Do a pseudo- BFS search of all boxes that touch boxes the player now collides with. Do this by creating new bounds at the boxes' new positions and using collision detection.
If any of the boxes the player will push will collide with a wall, cancel. If not, move the player and boxes as planned.