Discussion thread for day 22 of the Advent of Code - https://adventofcode.com/2023/day/22
D22 was a fun one! It was nice to have a pure workflow again (no pen/paper for today). Debugging took me longer than I thought and it seemed like I kept building the same workflow over and over again, thinking it would work until I finished it for the n-th time and remembered why that method wouldn't actually work. I did end up getting things working, and watching my workflow run brought me great satisfaction today for some reason!
Algorithm:
1 | 2 | 2 | |
3 | 3 | ||
5 | 3 | 3 | |
4 | 5 |
^The bottom row of our table represents the ground plane (So bricks 4 & 5 aren't going anywhere). On the first iteration, the brown bold-ed bricks are able to drop down 1 unit into free space (Notice that even though brick 2 is in the air and could technically move down too, we won't move it yet because it sits on top of brick 3):
2 | 2 | ||
1 | |||
5 | 3 | 3 | |
4 | 5 | 3 | 3 |
2 | 2 | ||
1 | 5 | 3 | 3 |
4 | 5 | 3 | 3 |
^After the third iteration, all blocks are now unable to drop any further and the macro would be complete.
We can now solve part one, by adding the count of all blocks with nothing above them (bricks 1 & 2) with the count of all bricks with bricks above them, which all have multiple bricks below them (bricks 3 & 5;
Example 1) brick 3 has brick 2 above it, and brick 2 has both bricks 3 & 5 below, so brick 3 is valid. The same argument applies to brick 5.
Example 2) brick 4 has brick 1 above it, but brick 1 only has brick 4 below, so brick 4 is invalid).
4 | 4 | |
3 | 5 | |
1 | 1 | 2 |
ID_B | ID_T |
1 | 3 |
1 | 4 |
2 | 5 |
3 | 4 |
4 | |
5 |
Workflow:
Happy Solving!!!
Fun challenge...
...except I was too brain dead to optimize P2. Fortunately, brute force did work with a batch/iterative macro combo that ran in 18 minutes:
P1 - I think I had a similar logic to @CoG. The hardest part was figuring out how to organize the x,y,z grid for my macro to work correctly. My initial attempt left a lot of floating bricks with the full dataset:
Settle Macro (every other macro is some variation of this one or uses this one inside a batch macro):
P2 - Brute force all the way. I used a second workflow to pass the results from P1 since I didn't know how long it would take to run:
I learned the viz is very important for debugging again. Because I fell the blocks under the floor or insert a block into another block... At this quiz, the sample data did not work well.
In this macro, I got the position where the blocks is. In other words, these are the coordinates where the blocks touch each other.
And also, I need to consider the pattern below.
66
445
233
11
If I disintegrate the block 3, the block 5 will fall down. So I can NOT break the block 3. It took too long time to find this pattern.
Part 2 :
I can use the result of part 1 macro. I created a list that the block supports another one independently, so I look at the parent-child relationship one block at a time based on this list. In order to view each block one by one, iterative macro is called in a batch macro, and the iterative macro itself counts the number of bricks that fall when one brick is destroyed, and the batch macro runs the entire process.
Batch macro :
Iterative macro :
Final workflow :
Tetris was nostalgic for me because I used to make it with Z80 assembly. Part2 was solved with the relationship between the supporting blocks.
@gawa - Thanks for sharing your solution. I've been stuck on Part 2 for WEEKS and it's been killing me. I like how you were using the Append Tool since I was doing all sorts of weirdness and extra tools and stuff whereas a simple Append would have made my life easier. I FINALLY got my 2nd star :)
@Carolyn Happy to hear that my WF helped you somewhat! Count&Append is a nice combo to judge break from loop.
It seems now you have 4 puzzles to go...good luck!
@gawa Thank you!! Yeah, closing it on it. I'm super stuck on D20, but hopefully when I revisit it, I'll have a flash of insight :)