Warning
Spoilers ahead! You have been warned.
- AoC Page ↗︎
- Part 1 Code (TypeScript)
- Part 2 Code (TypeScript)
- Puzzle Input
Wow, what a day. This took me around 2 hours to complete. I really question my programming skills sometimes. In day 5, you have to ship cargo! Rust reference?! Parse an annoying string, and move cargo from one stack to another stack. Again, I did it in TypeScript.
You have to first parse a long string first with two sections: the actual stacks information and instructions. This took
me way longer than it should, and regex makes stuff 10x more simple. For part 1, you have to loop over each instruction
and remove the last n elements (JS hint: .splice()
/.slice()
) from your old stack. Then, reverse the array and add
the moving crates (JS hint: .push()
and spread operator, or, [...old, ...new]
, make sure new
is reversed!) to your
new stack. Part 2 so far was the most relatively simplest to their preceding part. You basically don't reverse the
moving crates when adding it to the new stack. In JS, that's as simple as removing wherever your .reverse()
is.