Advent of Code - Day 15

Note: This topic is to talk about Day 15 of the Advent of Code.

For general discussion about the Advent of Code 2018 and links to topics of the other days, see this topic.

Here is my take on day 15. This one was quite tedious, so I decided to work in small steps, and immediately introduced the Board and Unit modules to separate concerns. Owing to that approach, I almost got it right in the first attempt :slight_smile:

1 Like

Here is my solution for day 15.

Unfortunately, I didn’t introduce structs and modules, so I wasted time updating code all over the place when I found I needed to change the representation. When I got it working on all examples, I found that it was far too slow to finish in a reasonable amount of time, so I spent more time optimizing the path finding code.

The code as it looks now finishes both parts in less than 30 minutes on my computer with my input. I am sure there are more optimizations that can be done, but I had to start working on the next day’s puzzle.

I didn’t optimize my code at all, but it takes about 7 sec to finish both parths. I think the key reason was that I used breadth-first search (implemented here) to find the paths to closest enemies.

Interesting. I also use breadth-first search, but for some reason my implementation is much slower. I probably have a performance bug somwhere, doing more work than needed or using more memory than needed. It seems to be particularly slow when a unit does an unsuccessful search over the complete board without being able to find a square in enemy range.

I finally have a way-too-slow solution to Day 15:

I streamed it several times, but they aren’t worth watching.