AoC 2024: Day 15

Main thread for Day 15 of the 2024 advent of code. Feel free to discuss the challenge and ask questions. If particular discussions become large, we can break them off into new threads.

Some Rules:

  1. Please try to keep spoilers within spoiler tags. This is done by typing [spoiler]text to be blurred[\spoiler]. If you have longer sections you can also use the [details=“Title”] tags.
  2. Have Fun

Day 15 Challenge

Templates:

Resources:

Previous days discussions

Day 1: AoC 2024: Day 1
Day 2: AoC 2024: Day 2
Day 3: AoC 2024: Day 3
Day 4: AoC 2024: Day 4
Day 5: AoC 2024: Day 5
Day 6: AoC 2024: Day 6
Day 7: AoC 2024: Day 7
Day 8: AoC 2024: Day 8
Day 9: AoC 2024: Day 9
Day 10: AoC 2024: Day 10
Day 11: AoC 2024: Day 11
Day 12: AoC 2024: Day 12
Day 13: AoC 2024: Day 13
Day 14: AoC 2023: Day 14

Only had time for part 1 today. Part 2 doesn’t seem significantly more difficult, just more of a pain to implement. My initial idea for part 2 is to use a stack to keep track of the boxes to have to move up and down.

https://zigbin.io/b2a499

Part 2 was a bit of coding.
Did a visualisation (prior to solving it completely, this helped find bugs in the logic.

Source: aoc2024/src/day15.zig at main · p88h/aoc2024 · GitHub
Visualisation: https://youtu.be/vJ9ar_q78So

Benchmark:

        parse   part1   part2   total
day 15:  4.3 µs  0.1 ms  0.2 ms  0.4 ms (+-1%) iter=101
1 Like

0.5ms. That was more code than the other days. I try to avoid it when possible, but in this case recursion was cleaner.

https://zigbin.io/f1d606
Using this multidimensional array that I finally extracted to its own file:
https://zigbin.io/c43da6

Nice visualization @p88h :slight_smile: