advent of code day 3: i might be r-slurred edition

idk how to do multi line spoilers lol



letters = ['','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']

total_score = 0

team = []

for line in open("input.txt"):
    team.append(line.strip())

for i in range(2, len(team), 3):
    for letter in team[i]:
        if letter in team[i-2] and letter in team[i-1]:
            total_score += letters.index(letter)
            break

print(total_score)

some real caveman shit but it works

80
Jump in the discussion.

No email address required.

static inline unsigned getPriority(char elem)
{
	if(elem >= 'a' and elem <= 'z')
		return elem - 'a' + 1;
	
	if(elem >= 'A' and elem <= 'Z')
		return elem - 'A' + 27;
	
	abort();
	return 0;
}

static inline std::vector<char> toVec(const std::string &str)
{
	std::vector<char> t;

	for (char const &c: str)
		t.push_back(c);


	std::sort(t.begin(), t.end());
	t.erase( unique( t.begin(), t.end() ), t.end() );

	return t;
}

int main()
{
	std::string rucksack;
	unsigned long long points = 0;
	size_t index = 0;
	std::vector<char> group_sacks[3];

	while(std::cin >> rucksack)
	{
		group_sacks[index] = toVec(rucksack);
		auto secondComp = toVec(rucksack.substr(rucksack.length() / 2));

		if(index == 2)
		{
			std::vector<char> i1, i2;
			std::set_intersection(
				group_sacks[0].begin(), group_sacks[0].end(),
				group_sacks[1].begin(), group_sacks[1].end(), 
				std::back_inserter(i1));
			
			std::set_intersection(
				group_sacks[2].begin(), group_sacks[2].end(),
				i1.begin(), i1.end(), 
				std::back_inserter(i2));
			
			for(char c: i2)
				points += getPriority(c);

			index = 0;
		}
		else
			index ++;
	}

	std::cout << points << std::endl;
}
Jump in the discussion.

No email address required.

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