Day 18 - Solutions
What a relief today! Anyway, I need to think on how to optimize part 2 https://github.com/zelark/AoC/blob/master/src/zelark/aoc_2024/day_18.clj
https://gitlab.com/maximoburrito/advent2024/-/blob/main/src/day18/main.clj You could definitely bsearch part2 to speed it up, but there's really no bother. I definitely got tripped up on the wording, expecting there to be some trick. Will the blocks fall from the top? Do corrupted blocks come in every step? Why is the example so simple? But no... It was just trivial search...
Yeah, binary search would speed it up, but maybe there are some other techniques
Rarely seen a more straightforward a-star application. Binary search for part2, although the first time I did it, I just ran it linearly. Nothing much to say really. Both parts run under 100ms.
> Will the blocks fall from the top? I thought about https://adventofcode.com/2022/day/14 at the moment
hm didn’t think of binary search, runs in like 6 seconds in any case
https://github.com/rjray/advent-2024-clojure/blob/master/src/advent_of_code/day18.clj
Simple BFS for part 1, and semi-brute-force of just adding the blocks in order and running the fn of part 1 until it fails to reach the end for part 2.
I must be doing something wrong in how I actually run my code. It never runs as fast as the times other people report. I general run it through lein, specifically lein run .... Is there a step (like compiling) that I'm missing?
Ok, I put binary-search in my core. Updated part 2, now it takes about 50 msecs. Btw, I just run it with time a few times, no compiling, and parsing included.
https://github.com/zelark/AoC/blob/master/src/zelark/aoc_2024/day_18.clj
it's EASY! I coded binary search out of pickiness (uh, instead of manually just plugging numbers into the repl) and it worked the first time. https://github.com/tildedave/advent-of-code/blob/main/src/advent2024/day18.clj
Here’s today’s: https://github.com/bhauman/adv2024/blob/main/src/adv2024/day18/sol.clj Dijkstra’s and 2 minutes for part 2
OK binary-search that makes sense. Funny that I implemented it yesterday …. [edit] the above is updated with binary search :)
I kind of want to re-code it using some approach that keeps the path and re-calculates based on some intermediate structure as the bits fall.
might help to do it in reverse in that case. Start with the all the bytes and take them away one at a time …
Is it me or is 2024 markedly easier than past years?
It seems easier, but I’m always afraid to invite the wrath of the AOC gods …
Yeah, I'm totally jinxing it.
I guess day 9 has been the most annoying so far.
I hope it won't go crazy in the coming days.
🙏
BFS on both parts, second based on reverse (20ms). https://github.com/genmeblog/advent-of-code/blob/master/src/advent_of_code_2024/day18.clj
I also did reverse for part 2
400ms though 🤔
used ubergraph https://github.com/tschady/advent-of-code/blob/main/src/aoc/2024/d18.clj
running behind, but we are live!