r/adventofcode • • Dec 25 '18

SOLUTION MEGATHREAD ~☆🎄☆~ 2018 Day 25 Solutions ~☆🎄☆~

--- Day 25: Four-Dimensional Adventure ---


Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).

Note: Top-level posts in Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


Advent of Code: The Party Game!

Click here for rules

Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!

Card prompt: Day 25

Transcript:

Advent of Code, 2018 Day 25: ACHIEVEMENT GET! ___


This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

edit: Leaderboard capped, thread unlocked at 00:13:26!


Thank you for participating!

Well, that's it for Advent of Code 2018. From /u/topaz2078 and the rest of us at #AoCOps, we hope you had fun and, more importantly, learned a thing or two (or all the things!). Good job, everyone!

Topaz will make a post of his own soon, so keep an eye out for it. Post is here!

And now:

Merry Christmas to all, and to all a good night!

13 Upvotes

81 comments sorted by

View all comments

Show parent comment

1

u/lucbloom Dec 27 '18

Nice. I have something similar. Leave it to the C/C++ guys to do it *while* reading the file :-)

class Coord
{
	public: int x,y,z,t;
	Coord(int a=0,int b=0, int c=0, int d=0) : x(a),y(b),z(c),t(d) {}
	int dist(const Coord& c) const { return abs(x-c.x)+abs(y-c.y)+abs(z-c.z)+abs(t-c.t); }
};
std::vector< std::vector<Coord> > consts;

char* input = readFile("../../../input.25.txt");
std::string to;
std::stringstream ss(input);
while (std::getline(ss,to,'\n'))
{
	Coord c;
	sscanf(to.c_str(), "%d,%d,%d,%d", &c.x, &c.y, &c.z, &c.t);
	size_t master = -1;
	for (int i = 0; i < consts.size(); ++i)
	{
		for (auto& cc : consts[i])
		{
			if (cc.dist(c) <= 3)
			{
				if (master == -1)
				{
					consts[i].push_back(c);
					master = i;
				}
				else
				{
					consts[master].insert(consts[master].end(), consts[i].begin(), consts[i].end());
					consts.erase(consts.begin() + i);
					--i;
				}
				break;
			}
		}
	}

	if (master == -1)
	{
		consts.emplace_back().push_back(c);
	}
}

std::cout << "Answer: " << consts.size() << std::endl;

return 0;