adventofcode

roklenarcic 2023-12-17T07:10:07.571169Z

Day 17 - Solutions

roklenarcic 2023-12-17T07:10:18.798659Z

Was another quite easy day.

๐Ÿ˜ 2
roklenarcic 2023-12-17T07:10:50.263079Z

https://gist.github.com/RokLenarcic/5edaaa4a667217a8bf6f298163f48337

๐Ÿ‘ 1
Ivana 2023-12-19T17:58:17.937049Z

This was challenging task for me, thought on it during 3 days and only today created usable algorythm, although working for both parts. Thanks to author of AOC, this task for me was times harder than all other ones for now ๐Ÿ˜Š

roklenarcic 2023-12-19T19:36:21.625169Z

If you used A*, what was your heuristic for max path length to goal?

Ivana 2023-12-19T21:14:23.371929Z

I used deterministic algorythm without any heuristics

roklenarcic 2023-12-19T21:18:55.631909Z

Isnโ€™t that just dijkstra then?

Ivana 2023-12-19T21:20:27.715579Z

No, just very tweaked Bellmann-Ford-like one

jurjanpaul 2023-12-20T12:28:42.759629Z

Intuitively implemented 'shortest path' search with Manhattan distance heuristic, but didn't get the prioritization quite right at first, causing the code to take prohibitively long on my platform of choice (#scittle on my iPhone 8; no clojure.data.priority-map or more advanced libs). Studied A* again and learned how to use sorted-set properly. Part 1 now finishes within 30s and I am happy to accept that. ๐Ÿ™‚

roklenarcic 2023-12-20T12:29:41.092019Z

manhattan distance is wrong heuristic

roklenarcic 2023-12-20T12:30:46.586339Z

Consider field 0,0 -> 10, 10, you are on part 2, and your current position is 9,9. What is the maximum remaining path?

jurjanpaul 2023-12-20T12:42:11.794569Z

Manhattan only for the lower bound: 1 + 1 = 2 in your example. But yes, a more realistic lower bound, if computable, would converge faster. I only just read part 2. Your solution seems to work without an explicit heuristic for the cheapest path to the goal... ๐Ÿค”

roklenarcic 2023-12-20T12:44:34.617119Z

doesnโ€™t need oneโ€ฆ

roklenarcic 2023-12-20T12:45:07.953759Z

I see that I got my idea about A* backwards

roklenarcic 2023-12-20T12:45:30.002269Z

the heuristic function has to return less or equal to the real shortest path

roklenarcic 2023-12-20T12:45:42.063859Z

I thought it was more or equal

jurjanpaul 2023-12-20T13:29:08.641639Z

Interestingly, indeed simply estimating the remaining cost to be 0, turns out to not be significantly slower in this case.

roklenarcic 2023-12-20T13:29:30.136909Z

yeah because the rules take you all over the place

roklenarcic 2023-12-20T13:29:51.847849Z

hard make a good heuristic

roklenarcic 2023-12-20T13:30:25.546029Z

My guess is that it would have to do something with coordinates and mod 3 or something to be better

Aleks 2023-12-17T11:40:50.230569Z

My part 1 runs 2.5 secs, and part 2 runs 7.5 secs https://github.com/zelark/AoC/blob/master/src/zelark/aoc_2023/day_17.clj

2023-12-17T13:22:55.037029Z

https://gitlab.com/maximoburrito/advent2023/-/blob/main/src/day17/main.clj?ref_type=heads I've been out sick for a bit and have quite a few days to catch up on. I feel a bit rusty as I had to finish this in the morning despite being a relatively straightforward search problem...

gabor.veres 2023-12-17T15:18:58.551769Z

@zelark, can you push your zelark.aoc.core with the astar implementation you are using at https://github.com/zelark/AoC/blob/7c0ba284618adecec81aa9631e180ad516a193d1/src/zelark/aoc_2023/day_17.clj#L37? Very nice aoc specific library btw, but this function is missing in the repo. I'm curious! Thanks!

Aleks 2023-12-17T15:26:03.576219Z

@gabor.veres thanks. Somehow I forgot to push it. In a nutshell itโ€™s a copy of astar-search implementation with a few improvements. Here we go https://github.com/zelark/AoC/blob/6d8ae4bb8d33efc47758076c2ed47875cde8ae2c/src/zelark/aoc/core.clj#L190

๐Ÿ‘ 1
Aleks 2023-12-17T17:53:29.048629Z

Forgot I have my g2/plus function for adding delta. Now it is a bit faster 6.2 secs for part 2 ๐Ÿคฉ