Advent of Code 2022 Day 14 (BaseA Style)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Took about an hour and change but got there for p1!
1. Workflow to get boundaries/field mapping of rocks and such
2. Batch Macro to run the same initial point
3. Iterative macro to check each step and overwrite existing file with updated point once stable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Well, I set a personal record for number of macro iterations... 1.8 million (before it failed due to a memory error). Needless to say, there was a better way to solve part 2 than brute force iteration 😂
 
 
 
Part 2: I started by tracking the grains of sand individually, brute force iteration. After 600,000, this was all the progress it had made:
 after 1.8 million iterations and 10 hours, it had only gathered 15,000 grains of sand. This is ~50% of the total grains of sand. I decided I needed a new approach.
Part 2, new approach: start with the entire sand pyramid as if there were no rocks. Then, subtract out all the grains of sand blocked vertically by the rocks. Add back sand that shifted left and right. Runs in 10 seconds.
 
 
Visual representation of part 2 answer: 
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
In the true spirit of Red-Green-Refactor - my solution to day 14 is awful - and it takes 18 hrs and 43 mins to solve part 2 on a 32 thread 2nd gen ThreadRipper with 64GB of RAM. If this means nothing to you - then the summary is that my solution is terrible and would take a few days to complete on a regular laptop.
however - it completed - any updates to this can only get better :-)
it's a nested loop:
- Outer loop iterates until either stuff starts falling off the bottom of the page, or it builds up to 500,0
- inner loop iterates over a particular grain until it either comes to rest or falls off the bottom of the page.
One thing I did that made this able to run in JIST 18.75 hours - was that I clean up the data every outer loop - and remove any cell that is fully surrounded - that means that I'm only ever iterating over ~1500 or so rows of data, even though the overall solution was ~28691 grains of sand.
it makes a big difference - the stripped down version looks like this:
Compared to the version that has all the cells that are surrounded (and not going anywhere) that looks like this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
workflow:
macro:
my macro each loop performs
1. move down the sand to the first wall
2. generate 2 possible moves (left or right diagonally) keep first 1 (as always left)
3. generate new sand if no possible move
I stop when it took more than 30,000+ iteration.
to speedup. I change the birth point, which no longer always (500,0)
the new macro become:
1. move down the sand to the first wall (update birth point to here, which save lot of loop from (500,0)
2. delete the birth point if the sand is reaching this birth point. (return to higher birth point)
3. generate 2 possible moves (left or right diagonally) keep first 1 (as always left)
4. generate new sand from point 1. with lowest birth point (max_y)
B is birth point, got multi text mean the birth point deleted due to the sand is reach the birth point.
it reduced to 3000+ loop.
part 2:
I assume it will cover all the blocks, we need not process sand one by one.
we can just analysis left up, up, right up from current cells.
so, start with limit the space by triangle
fill the triangle's side with sand, as top layer of sand.
bottom is the floor.
macro:
1. check all blank position from the triangle, from top to bottom. line by line. (i.e., by Y level)
2. check neighbors from 3 directions above it (left up, up, right up) for each position.
3. if any neighbors got "Sand" then it will be "Sand".
hence, it will only take loop based on max_y.
here the result.
hello @clmc9601 can you share me the workflow visualize part. or link for config it?
I tried to build one, but it not working, it still okay in map tool's preview but output only show as block.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Had to refactor part 2
Workflow:
Poorly laid out macro:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Sure, @PangHC, workflow attached. I'm also posting all of my solutions here on GitHub.
