Day 15: Warehouse Woes
Megathread guidelines
- Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
- You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL
FAQ
- What is this?: Here is a post with a large amount of details: https://programming.dev/post/6637268
- Where do I participate?: https://adventofcode.com/
- Is there a leaderboard for the community?: We have a programming.dev leaderboard with the info on how to join in this post: https://programming.dev/post/6631465
10 Comments
JRaccoon@discuss.tchncs.de · 2 pts · 1y
TypeScript
Not very optimized code today. Basically just a recursive function ::: spoiler Code
:::
Gobbel2000@programming.dev · 2 pts · 1y
Rust
Part 2 was a bit tricky. Moving into a box horizontally works mostly the same as for part 1, for the vertical case I used two recursive functions. The first recurses from the left and right side for each box just to find out if the entire tree can be moved. The second function actually does the moving in a similar recursive structure, but now with the knowledge that all subtrees can actually be moved.
Lots of moving parts, but at least it could very nicely be debugged by printing out the map from the two minimal examples after each round.
::: spoiler Solution
:::
Also on github
mykl@lemmy.world · 2 pts · 1y
Dart
canMovedoes a recursive search and returns all locations that need moving, or none if there's an obstacle anywhere downstream. For part2, that involves checking if there's half of a box in front of us, and if so ensuring that we also check the other half of that box. I don't bother tracking whether we're double-checking as it runs fast enough as is.janAkali@lemmy.one · 2 pts · 1y
Nim
Very fiddly solution with lots of debugging required.
::: spoiler Code
:::
Codeberg Repo
ooterness@lemmy.world · 2 pts · 1y
Rust
The work is all in the "push" method. The robot pushes one square, which may chain to additional squares. HashSet probably isn't the optimal data structure, but it's good enough.
::: spoiler Large codeblock
:::
hades@lemm.ee · 2 pts · 1y
gentooer@programming.dev · 2 pts · 1y
Haskell
Runs in 12 ms. I was very happy with my code for part 1, but will sadly have to rewrite it completely for part 2.
::: spoiler Code
:::
VegOwOtenks@lemmy.world · 1 pts · 1y
Haskell
I'm late today, anyway here is my blazingly fast solution using haskell
::: spoiler Large codeblock
:::
Quant@programming.dev · 1 pts · 1y
Uiua
Put this one off for a bit and I'll put off part two for even longer because I don't want to deal with any pyramid-shapes of boxes at the moment.
The code for part one feels too long but it works and runs <2s so I'm happy with it for now ^^
Run with example input here
::: spoiler Code I decided to split the movement instructions lines further for aesthetic reasons when opening it in the online uiua pad since newlines are thrown out anyways.
:::
lwhjp@lemmy.sdf.org · 1 pts · 1y
Haskell
This was a fun one! I'm quite pleased with
moveInto, which could be easily extended to support arbitrary box shapes.::: spoiler Solution
:::
sjmulder@lemmy.sdf.org · 1 pts · 1y
C
3h+ train ride back home from weekend trip but a little tired and not feeling it much. Finished part 1, saw that part 2 was fiddly programming, left it there.
Finally hacked together something before bed. The part 2 twist required rewriting the push function to be recursive but also a little care and debugging to get that right. Cleaned it up over lunch, happy enough with the solution now!
:::spoiler Code
:::
https://github.com/sjmulder/aoc/blob/master/2024/c/day15.c