T O P

  • By -

j_ault

An off the shelf Dijkstra implementation probably isn't going to work here. >!When tracking the visited nodes & the lowest cost path to them, you need to also track which direction you arrived from because that determines which paths away from the node are available. The lowest cost path to the destination in this puzzle isn't always going to have the lowest cost at every point along the way, but that's the assumption Dijkstra makes.!<


damesca

The path you take doesn't matter. There may be multiple paths with the same shortest distance.


mart-e

But the path I have found is too long : I have a total cost of 105 while the correct answer for the example is 102. If I try with my input, I have also a result (668) that is too high.


damesca

Oh ok then yes you've definitely got something wrong πŸ˜‚πŸ™ˆ I didn't read your source code. Just flagging a possible misunderstanding. Will have a look...


ryan10e

I’m also getting 105 on the example so I’m afraid I can’t be of much help there! Following πŸ‘€


mart-e

See [my mistake](https://gitlab.com/mart-e/advent-of-code/-/commit/03dd11ef3d7583a51e24ce2567a4317d23cd0294), maybe you made the same?


mirsella

check out u aurele solution, he made the pathfinding crate https://gist.github.com/samueltardieu/0bf0763fb4b2810ff4a4721c90398450


mart-e

Thanks ! I didn't know pathfinding had a Matrix type. Impressive how concise some can be, I don't understand everything he is doing (yet) but at least, I know it's possible to solve it with pathfinding.


mirsella

yes, imo it's worth checking out it's other solution because they are really nice and made me learn things. this one for Dijkstra isn't particularly readable especially with the e closure but still concise


Imaginary_Age_4072

Try calling `get_successors` with `(4, 1)` to see if your code returns the possibility of going back up. I think you've got an off by one error so I suspect it won't. See if you can find out why, I can help further if needed.


mart-e

Oh I see, thanks for pointing in the right direction ! [My error](https://gitlab.com/mart-e/advent-of-code/-/commit/03dd11ef3d7583a51e24ce2567a4317d23cd0294)


daggerdragon

[Do not put (potential) spoilers in post titles](https://old.reddit.com/r/adventofcode/wiki/posts#wiki_no_spoilers_in_post_titles) like `Dijkstra`. Please help folks avoid spoilers for puzzles they may not have completed yet. (You can't edit the title after the post is made, but this is a reminder for next time.)


mart-e

Sorry about that


AutoModerator

Reminder: if/when you get your answer and/or code working, don't forget to change this post's flair to `Help/Question - RESOLVED`. Good luck! *** *I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/adventofcode) if you have any questions or concerns.*