igorb

igorb

Advent of Code 2024 - Day 18

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

Most Liked

bjorng

bjorng

Erlang Core Team

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.

lud

lud

Same here, solved easily, the brute force took something like 6 seconds.

Then I used binary search:

  • First drop 1024 items from the walls points
  • Create a base grid (with grid module) with those 1024 walls
  • Then do a binary search for n between 1 and length(rest_of_walls). For each try:
    • take with Enum.take(rest_of_walls, n) and add those walls to the grid.
    • return “search reasult is greater” if the path is possible
    • return “…is lower” if the path is not possible

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.

liamcmitchell

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 :queue like yours and got 42 seconds so much faster. Re-added binary search and it’s now 3 seconds including compilation.

Flo0807

Flo0807

My solution. I used Erlang’s queue data type for part 1. For part 2, I implemented a binary search, too.

Aetherus

Aetherus

I implemented my own priority queue with no duplicate values and lazy decrease-key operation.
Part 1 I used that priority queue to implement Dijkstra.
Part 2 I used a totally different approach. For each “byte” dropped down, I check if there are byte chunks horizontally, vertically, or diagonally adjacent to that “byte”, and merge those chunks with the new byte to form a larger chunk. Then I just need to find the first chunk over time that horizontally or vertically crosses the whole “memory space”.

Here’s my approach:

Where Next?

Popular in Challenges Top

LostKobrakai
This topic is about Day 9 of the Advent of Code 2020 . Thanks to @egze, we have a private leaderboard: https://adventofcode.com/2020/le...
New
bismark
Took me a minute to remember my binary math :smile: :grimacing:… import Bitwise __DIR__ |> Path.join("puzzle.txt") |> File.stream...
New
Aetherus
This topic is about the Advent of Code 2021 - Day 4. Thanks to @bjorng , we now have a new Private Leaderboard. The entry code is: 370...
New
bjorng
This topic is about Day 18 of the Advent of Code 2021. We have a private leaderboard (shared with users of Erlang Forums): https://adve...
New
igorb
I found today a bit tedious: advent-of-code-2024/lib/advent_of_code2024/day15.ex at main · ibarakaiev/advent-of-code-2024 · GitHub.
New
bjorng
Note: This topic is to talk about Day 2 of the Advent of Code 2019 . There is a private leaderboard for elixirforum members. You can joi...
New
Aetherus
This topic is about Day 4 of the Advent of Code 2020 . Thanks to @egze, we have a private leaderboard: https://adventofcode.com/2020/le...
New
rugyoga
Fairly straightforward Dijkstra’s algorithm import AOC aoc 2023, 17 do def compute(input, candidates) do {{max_row, max_col}, ite...
New
bjorng
This topic is about Day 6 of the Advent of Code 2021. We have a private leaderboard (shared with users of Erlang Forums ): https://adve...
New
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

We're in Beta

About us Mission Statement