igorb
This puzzle was a nice break after the difficult Day 17! For part 2, I implemented a binary search to find the necessary coordinate faster, but considering the input size this was definitely not necessary. advent-of-code-2024/lib/advent_of_code2024/day18.ex at main · ibarakaiev/advent-of-code-2024 · GitHub
Trending in Challenges
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
bjorng
Yes!
Having quickly solved both parts, I had time to experiment with different ways of managing the queue. My initial implementation used gb_sets; I ended up using queue.
The combined runtime for both parts is 4.5 seconds.
https://github.com/bjorng/advent-of-code/blob/main/2024/day18/lib/day18.ex
lud
Same here, solved easily, the brute force took something like 6 seconds.
Then I used binary search:
nbetween1andlength(rest_of_walls). For each try:Enum.take(rest_of_walls, n)and add those walls to the grid.Of course there is no answer for “search result is equal” so I had to modify my binary search algorithm to detect ties and return them.
Part two is 13ms on my machine.
https://github.com/lud/adventofcode/blob/main/lib/solutions/2024/day18.ex
liamcmitchell
I thought that was long until I saw you are brute forcing part 2, no binary search.
I timed my first implementation without binary search and got 213 seconds (2013 MBP). Switched the pathfinding to use
:queuelike yours and got 42 seconds so much faster. Re-added binary search and it’s now 3 seconds including compilation.https://github.com/liamcmitchell/advent-of-code/blob/main/2024/18/1.exs
rvnash
Part 1 I solved using a simplified version of the path finding algorithm from Day 16.
Part 2: I guess there is probably some way to trim all possible paths as the bytes fall and cut them off, until the link to the end is severed. But I just brute forced it, checking all bytes sequentially until it failed to find a path, and it finished in 4.5 seconds.
https://github.com/rvnash/aoc2024/blob/main/lib/d18.ex
Flo0807
My solution. I used Erlang’s queue data type for part 1. For part 2, I implemented a binary search, too.
https://github.com/Flo0807/adventofcode/blob/main/2024/18.livemd
rvnash
Ok, switched mine to using a binary search instead of brute force, and times dropped to the ms range. Thanks for the idea.
lkuty
For part 1, I thought I will use libgraph and A*. But the code below does not find a path. I cannot figure out what is the problem here. I could solve it differently but I liked the idea of using a graph library, mentioned previously by @Aetherus I think.
Sorc96
I used libgraph for a challenge back in 2021 thinking I would be done with it quickly instead of implementing a custom algorithm. There was an issue with a hashing function for nodes creating a lot of collisions, so while the example worked fine, the graph for the actual input was missing a few nodes.
There was a fix that allowed for a custom hashing function to be supplied, but the old one was still hardcoded in one place. So I ended up spending a lot of time figuring this out and patching the local copy of libgraph to use my “hashing” function, which was really just the identity function.
I don’t know if this problem is still present, but I recommend checking whether the number of nodes in your graph seems correct.
sevenseacat
Man, this was a nice change of pace from yesterday.
https://github.com/sevenseacat/advent_of_code/blob/main/lib/y2024/day18.ex
This builds up an empty graph of the correct size with edges pointing back and forth between coordinates, and then adds “walls” for the falling bytes.
Part 1 is pretty straightforward - add 1024 walls, get the shortest path.
Part 2 uses a binary search over the length of the byte list to see where the first error happens. There’s probably still room for optimization there, but I’m happy enough with it.
lkuty
It looks like there is a problem with path finding in general with undirected graphs. get_shortest_path doesn't work correctly on undirected graphs · Issue #37 · bitwalker/libgraph · GitHub and Incorrect A* pathfinding with undirected graph · Issue #11 · bitwalker/libgraph · GitHub