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.

C++ chads simply cannot stop winning


#include <iostream>
#include <string>
#include <vector>
#include <regex>
#include <list>
#include <iterator>

#define N_STACKS 9

// G-d forgive me bc I used C++ Slowpoke regex
std::regex in_reg("move\\s(\\d+)\\sfrom\\s(\\d+)\\sto\\s(\\d+)");

int main()
{
	std::list<char> stacks[N_STACKS];
	std::string sbuf;

	while(std::getline(std::cin, sbuf))
	{
		if(sbuf[1] >= '0' and sbuf[1] <= '9')
			break;
		
		for(auto i = 0; i < N_STACKS; i ++)
			if(sbuf[4*i + 1] != ' ')
				stacks[i].push_back(sbuf[4*i + 1]);
	}

	// Empty line
	std::getline(std::cin, sbuf);

	// main loop
	while(std::getline(std::cin, sbuf))
	{
		std::smatch match;
		std::regex_search(sbuf, match, in_reg);

		auto move_cardinality = std::stoul(match.str(1));
		auto from_index = std::stoul(match.str(2)) - 1;
		auto to_index = std::stoul(match.str(3)) - 1;

		// PART A
		//for(auto i = 0; i < move_cardinality; i++)			
		//	stacks[to_index].push_front(stacks[from_index].front());

		// PART B
		auto it = stacks[from_index].rbegin();
		std::advance(it, stacks[from_index].size() - move_cardinality);

		for(auto i = 0; i < move_cardinality; i++, ++it)
			stacks[to_index].push_front(*it);
		
		for(auto i = 0; i < move_cardinality; i++)
			stacks[from_index].pop_front();
	}

	for(auto i = 0; i < N_STACKS; i ++)
		std::cout << stacks[i].front();
	std::cout << std::endl;

	return 0;
}
Jump in the discussion.

No email address required.

move_cardinality

LMAO I just can imagine you trying to come up with a descriptive variable name while still half asleep and coming up with that LOL

\\

accept R"(your\slord\sand\ssavior)"

Jump in the discussion.

No email address required.

:#marseynotes:

btw can you do scanf-like input with a std::istream?

Jump in the discussion.

No email address required.

Reported by:

No idea.

Jump in the discussion.

No email address required.

That PERIOD is micro-aggression. I'm literally shacking rn

Jump in the discussion.

No email address required.

"move\s(\d+)\sfrom\s(\d+)\sto\s(\d+)"

could just do something of the order of /\d+/g, match all, and be done with it

Jump in the discussion.

No email address required.



Now playing: Welcome to Crocodile Isle (DKC2).mp3

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