Unable to load image

Advent of Code Day 5, AKA Stacks 101 :marseyinabox:

I actually stayed up to get a semi-decent score for once (being a eurocel for this is suffering). How are you all faring with shifting boxes around?

![](/images/16702184438592093.webp)

26
Jump in the discussion.

No email address required.

wow, today's puzzle was way easier than I thought it was gonna be from skimming some of these comments (I only skimmed them and even then, only the ones that weren't in C++ and trust me I cannot even begin to comprehend Python). it was probably about as easy as Day 1.

you can use either a regex or, if you parse the line into a list of strings, you can just grab the second, fourth, and sixth string since each line is always six words

@DrClaus had a better idea than me using std::list instead of std::vector since you can use pop_front() with a list, I had to either work backwards from the end of the vector or create a sub-vector of just the last n elements and work forwards; I figured the latter was lazier since I didn't have to think too hard on doing "size()-numBoxes" or some shit, just pop the back and insert at the front of the sub-vector.

from there it's absolutely just as simple as doing:

// part 1
for(auto i = 0; i < numBoxes; i++)
{
    char c = stacks[from].back();
    stacks[from].pop_back();
    stacks[to].push_back(c);
} 

or

// part 2:
// create subvector
substack.clear();
for(auto i = 0; i < numBoxes; i++)
{
    substack.insert(substack.begin(), stacks[from].back());
    stacks[from].pop_back();
}

// push from subvector to mainvector
for(auto i = 0; i < numBoxes; i++)
{
    stacks[to].push_back(substack.front());
    substack.erase(substack.begin());
}

where "from" is an integer that is the fourth element in each line (converted to an int), "to" is the sixth, and "numBoxes" is the second. fuck regexps, they can go to hell. do this for each line of input and you get the result.

C++ chads do indeed stay winning.


https://i.rdrama.net/images/1737673901UvHSoHNlCgDLyg.webp

Current HP: 8/75

Current Mana: 130/250

Inventory:

* 50 Gald

Jump in the discussion.

No email address required.

Mommy is soooo proud of you, sweaty. Let's put this sperg out up on the fridge with all your other failures.

Jump in the discussion.

No email address required.



Now playing: Donkey Kong December National Anthem.mp3

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.