Conversation
Rather than populating 2704 cells up front, then running the maze until all (reachable) cells have been visited, it is more efficient to populate the grid as we explore, and to quit exploring as soon as we have our answer. Cuts runtime from 6.4us to 3.1us on my machine. It is not worth the overhead of trying to steer the part 1 solution with an A* search.
|
For curiosity's sake, I coded up an A* solution (the heuristic being: |
|
I noticed there were no unit tests, even though the puzzle description DOES give a part 1 example of distance to 7,4. Another possible refactor would be splitting out a testable search, but lazy computation then runs into recomputing maze points per part rather than the current setup of solving both parts at once. |
Description
Rather than populating 2704 cells up front, then running the maze until all (reachable) cells have been visited, it is more efficient to populate the grid as we explore, and to quit exploring as soon as we have our answer. Cuts runtime from 6.4us to 3.1us on my machine.
It is not worth the overhead of trying to steer the part 1 solution with an A* search.
Type of change
Checklist
using the same naming conventions. Code should be portable, avoiding any architecture
specific intrinsics.
cargo testcargo fmt -- `find . -name "*.rs"`cargo clippy --all-targets --all-featuresFormatting and linting also can be executed by running
just(if installed) on the command line at the project root.