Search
[Rust] Optimizing day 17 (spoilers)
Anybody got some ideas to optimize today? I've got it down to 65ms (total) on my desktop, using A* with a visitation map. Each cell in the visitation map contains (in part 2) 16 entries; 4 per direction of movement, 1 for each level of straightaway. In part 2, I use a map with 11 entries per direction.
Optimizations I've implemented:
- use a 2D array instead of a hashset/map. No idea how much this saves, I did it in the first place.
- the minimum distance for a specific cell's direction + combo applies for higher combo levels as well for part 1. For part 2, if the current combo is greater than 4, we do the same*. Gains about 70(!!) ms
- A* heuristic weighting optimization, a weight of about 1% with a manhattan distance heuristic seems to gain about 15 ms (might be my input only tho)
*Correctness-wise: the reason we're splitting by direction is because there's a difference between being at a cell going up with a 3 combo but a really short path, and going right with a 0 combo but a lo
Part 2 poorly specified
The instructions for part 2 are missing info about how to handle the Four Of A Kind and a joker case. Wasted quite some time because I assumed that the remaining joker would remain unused, but turns out it turns your deck into Five Of A Kind.
Did everybody else just expect this?