Copyright | (c) Eric Mertens 2018 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
https://adventofcode.com/2018/day/22
This solution uses an A* graph search to find the shortest path through the cave to the target.
I picked an arbitrary cave size to memoize that was big enough to avoid
indexing errors. I use a boxed array so that I can lazily compute the
geologic indexes of the various locations in the cave. This also allows
me to recursively define geologic
and erosion
.
My A* heuristic is manhattan distance to the target plus a penalty for not holding the torch. (Accounting for the torch saves a small, but positive amount of time.)
Instead of modelling the tool being held directly I simply keep track of the risk number of the area I'm not allowed to enter.