General Discussions

Discuss any topics that are not product-specific here.

Advent of Code 2022 Day 14 (BaseA Style)

AlteryxCommunityTeam
Alteryx Community Team
Alteryx Community Team
Discussion thread for day 14 of the Advent of Code - https://adventofcode.com/2022/day/14
7 REPLIES 7
mmontgomery
11 - Bolide
11 - Bolide

Took about an hour and change but got there for p1!

Spoiler
Three Parts:
1. Workflow to get boundaries/field mapping of rocks and suchmmontgomery_0-1671053941144.png

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

mmontgomery_1-1671053989883.pngmmontgomery_2-1671054040187.png

 

 

clmc9601
13 - Pulsar
13 - Pulsar

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 😂 

 

Spoiler
Part 1: track each grain of sand as it fell. Once it couldn't fall further, mark it as settled and start a new grain falling. Once they start falling into the abyss, stop the macro. Runs in 5 minutes.

Screen Shot 2022-12-14 at 4.48.08 PM.png

 


Part 1 macroPart 1 macro

 

visual representation of part 1's answervisual representation of part 1's answer

 
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:

visualization of brute force after 600,000 iterationsvisualization of brute force after 600,000 iterations

 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.


Screen Shot 2022-12-14 at 4.48.30 PM.png

 

this section repeats several timesthis section repeats several times

 

Visual representation of part 2 answer:

Spoiler
Screen Shot 2022-12-14 at 4.15.58 PM.png

 

AkimasaKajitani
17 - Castor
17 - Castor

Thanks to the @clmc9601 's visualization, finally, I was able to clear this challenge.

 

Spoiler
AkimasaKajitani_0-1671328270070.png

Part1 macro : Sand simulator

AkimasaKajitani_1-1671328306443.png

Part 2 macro : Generate Sand vacant area

AkimasaKajitani_2-1671328331263.png

 

 

SeanAdams
17 - Castor
17 - Castor

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 :-)

 

Spoiler
My solution was messy - don't follow mine.

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.

SeanAdams_0-1672450040372.png




it makes a big difference - the stripped down version looks like this:

SeanAdams_1-1672450124092.png



Compared to the version that has all the cells that are surrounded (and not going anywhere) that looks like this

SeanAdams_2-1672450170832.png

 




PangHC
12 - Quasar

 

Spoiler
part 1:

workflow:
Pang_Hee_Choy_4-1672825896787.png

 

macro:
Pang_Hee_Choy_5-1672825946695.png

 


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.
Pang_Hee_Choy_3-1672822415150.png

 


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.
Pang_Hee_Choy_2-1672821922537.png
so, start with limit the space by triangle 
fill the triangle's side with sand, as top layer of sand.
bottom is the floor.
Pang_Hee_Choy_1-1672821328504.png


macro:

Pang_Hee_Choy_6-1672825983011.png

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.
Pang_Hee_Choy_0-1672821295053.png

 

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.

 

patrick_digan
17 - Castor
17 - Castor

Had to refactor part 2

Spoiler
I followed the way the example was written and had each piece of sand run it's journey one at a time. When that was going to take too long to solve, I realized I could add a new piece of sand every other step and everything would still go where it was supposed to.

Workflow:
patrick_digan_0-1672834887344.png


Poorly laid out macro:

patrick_digan_1-1672834966309.png

 

clmc9601
13 - Pulsar
13 - Pulsar

Sure, @PangHC, workflow attached. I'm also posting all of my solutions here on GitHub

Labels
Top Solution Authors