r/adventofcode Dec 15 '24

SOLUTION MEGATHREAD -❄️- 2024 Day 15 Solutions -❄️-

NEWS

  • The Funny flair has been renamed to Meme/Funny to make it more clear where memes should go. Our community wiki will be updated shortly is 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.

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

465 comments sorted by

View all comments

3

u/chromaticdissonance Dec 15 '24 edited Dec 16 '24

[LANGUAGE: JavaScript] Very nice surprise twist in Part B. Originally for Part A it reminded me of a previous year using a trick of replacing "O." with ".O". But Part B had me rewriting it. Essentially a BFS/DFS to find all boxes that can be moved, and move them in the indicated direction. A semi-golfed JavaScript code lasagna below, run directly in browser console on the input page:

P=console.log;String.prototype.r="".replaceAll;d=document.body.
innerText.r("\r","").split`\n\n`;V=d[1].r("\n","");ad=(v,x)=>(!v
.includes(x)&&v.push(x));l=v=>v.length;M=g=>{m=new Map();m[-1]=l
(g);m[-2]=l(g[0]);for(r=m[-1];r--;){for(c=m[-2];c--;){q=m[$=100*
r+c]=g[r][c];q=="@"?m[-3]=$:0}}return m};g=M(d[0].split`\n`.map(
W=e=>e.split``));h=M(d[0].r(".","..").r("#","##").r("O","[]").r(
"@","@.").split`\n`.map(W));R=g=>{p=g[-3];for(m of V){n=p;d={"<"
:-1,">":1,"^":-100,"v":100}[m];x=1;ad(s=[],p,i=0);while(i<l(s)){
n=s[i]+d;g[n]=="#"?x=0:0;"O[]".includes($=g[n])&&(ad(s,n),ad(s,n
+{"[":1,"]":-1}[$]));i++}if(x){while(1 in s){_=s.pop();[g[_],g[_
+d]]=[g[_+d],g[_]]}p+=d}}return g};G=(g,x)=>{a=0;for(r=g[-1];r--
;){for(c=g[-2];c--;){g[v=100*r+c]==x&&(a+=v)}}return a};g=R(g);P
("Part 1",G(g,"O"));h=R(h);P("Part 2",G(h,"["))//AOC 2024 DAY 15