liamcmitchell
Advent of Code 2024 - Day 20
I think I was clever by precalculating a search area to iterate over:
Part 1 example (5.7ms): 0
Part 1 input (93.0ms): 1417
Part 2 example (17.5ms): 0
Part 2 input (2382.3ms): 1014683
Most Liked
sevenseacat
This was a fun one! My initial implementation, before I looked at the data, tried a similar technique as the one with the guard and the rocks - delete each wall square, rerun path calculation, note difference - which worked for part 1, but was stupidly slow (like 70 seconds). And then I saw part 2 and it didn’t work there anyway ![]()
So I thought about it a bit, looked at the data, noted that every single floor square was part of the path, so I didn’t need to do any path recalculation - I just needed to slice parts out of the calculated path. And I didn’t even need to do that, I could index each item in the path and work out the difference.
Part 2 is a wee bit slow because I worked out allllll the options within 20 squares of each path square and calculated the difference, but it’s still under a second! ![]()
(and trying to optimize with Task.async_stream made it an order of magnitude slower)
Name ips average deviation median 99th %
day 20, part 1 13.45 74.33 ms ±6.84% 74.14 ms 83.83 ms
day 20, part 2 1.30 771.43 ms ±1.61% 767.13 ms 796.90 ms







