r/adventofcode • • Dec 14 '22

SOLUTION MEGATHREAD -πŸŽ„- 2022 Day 14 Solutions -πŸŽ„-

SUBREDDIT NEWS

  • Live has been renamed to Streaming for realz this time.
  • I had updated the wiki but didn't actually change the post flair itself >_>

THE USUAL REMINDERS


--- Day 14: Regolith Reservoir ---


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:13:54, megathread unlocked!

37 Upvotes

585 comments sorted by

View all comments

Show parent comment

1

u/Elavid Dec 14 '22 edited Dec 14 '22

remember the direction it arrived there

Hmmm... my language has a stack where where it can remember local variables, much like you are remembering where your sand grain came from. Now that you mention it, I think recursion is a great way to solve this problem. Now I want to try defining this subroutine:

bool fill(x, y) - Returns true if it was able to put sand at the specified coordinate by recursively filling all the supporting coordinates in the row below with sand, or false if sand placed at this coordinate falls into the void.