r/adventofcode • u/BlueTrin2020 • Dec 17 '23
Help/Question [2023 Day 17] Why can you only cache pos + dir in this one?
When I did this one, I cached (pos, dir, chain) cost, but when I checked the other people solutions, I can see that most people cached only pos + dir.
Isn't it possible that you reach the same point with a different number of moves in the same direction and a lower cost even though the total length is higher?
Is there something implicit in the puzzle that makes it that you can only store pos+dir and discard anything subsequent path that has the same pos+dir than a previously seen path?
Edit: I realised only now that the solutions not checking the cost, are using a heapq so because they always solve the lowest cost solution, using a priority queue, they only need to check if the position has been seen
Edit2: if we store only the turns this avoids having to store how many steps you have done so far
View all comments
35
u/[deleted] Dec 17 '23
[removed] — view removed comment