Discussion thread for day 9 of the Advent of Code - https://adventofcode.com/2024/day/9
first?
There are many optimizations that can be made here to shorten time needed for Part 2 (I have only used a few, but have a V2 that I'm working on). Current workflow runs in ~20 minutes:
V2 (Part 2 runs in ~8 minutes):
File Data | File Size |
0 | 5 |
. | 2 |
1 | 3 |
2 | 1 |
It seems like there is opportunity for further optimization, but this is what I have for now.
part1 was simpler than I thought at first glance. I tried to create Iterative macro but I realized it's not needed after 1 hour.
For part2, I just configured the required logic into Iterative Macro. No special trick is applied and it took 11 min.
I suppose there should exist a lot of trick to speed up but cannot come up with it for now.
My solution.
P2 was tough Challenge. My WF run in 9min for P1 and P2.
Solved!
I realized that the logic was incorrect, so I had to remake the workflow that I had created several times.
Part1: No macro
I solved it by breaking down the file into rows, reversing the order of free space, and joining them by row position. However, free space is larger than files, the end will be a bit strange, so the key point was how to deal with that.
Part 2:
It would be a lot of work to break it down row by row, so I calculated the number of files and the free space and stuff them one by one into the free space from the back ID files. There are a total of 10,000 IDs, so I just repeated this 10,000 times. My workflow took 8 min for part1 and 2.
Day9. More in spoiler
Finally finished up with day 9! Part 1 was fine. Explored a few different routes for part 2 and got there after a bit of nonsense.