bjorng
Erlang Core Team
Note: This topic is to talk about Day 21 of the Advent of Code.
For general discussion about the Advent of Code 2018 and links to topics of the other days, see this topic.
Trending in Challenges
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










First 3 of 3 Posts
bjorng
Here is my solution for Day 22.
I finished part 1 one quickly.
Embarrassingly, I then spent a lot of time on part 2, only to discover that I had a bug in the erosion level calculation. Despite the bug, I got the correct result for both the example and my input for part 1.
When I had fixed the erosion calculation bug, my code for finding the fastest path worked the first time I tried running on the example.
Then, of course, it didn’t finish running on the real input data. I then added a heuristic to prune paths that couldn’t possibly be faster than the already found path.
With that final fix, my program finished in about one and a half minutes.
sasajuric
Here is my take. Part 1 is pretty straightforward. I solved part 2 by doing a breadth-first search in 3D. It finishes in 50sec which doesn’t make me happy, but on the upside, at least it worked in the first attempt. Reading on the reddit thread, I now see that Dijkstra’s algorithm would be the proper solution that would finish much faster. I’m somewhat annoyed that I didn’t even think of it, but such is life I guess
stefanchrobot
On the flipside I went with Dijkstra straight away, but it took me a considerable amount of time to realize that it cannot be applied as-is. The reason is that the relaxation rule (dist[u] + length(u, v) < dist[v]) breaks because going along the “longer” edge (that is, switching gear) may pay off better in the long run. To solve that, one needs to do a “3D” version of the algorithm, that is, keep the minimum (tentative) distance for each combination of location and gear.
Once I got that down and the example worked, the key thing was to use priority queue in the implementation. Since there is none in the standard lib, I used a plain
MapSet+Enum.min_bywith the tip from Wikipedia:With that, I arrived at the solution after a couple of seconds even if I enlarged the cave by plain experimentation so that I could find the globally shortest path.