Advent 2022 day2 & day3

This commit is contained in:
Jos van Goor 2022-12-03 10:48:26 +01:00
parent 68a75987e2
commit 104f034568
6 changed files with 2923 additions and 0 deletions

View file

@ -0,0 +1,26 @@
#include <fmt/format.h>
#include <iostream>
#include <set>
int main()
{
int result = 0;
while (true)
{
std::string packing;
std::getline(std::cin, packing);
char double_packed{};
std::set<char> c1{packing.begin(), packing.begin() + packing.size() / 2};
std::set<char> c2{packing.begin() + packing.size() / 2, packing.end()};
std::set_intersection(c1.begin(), c1.end(), c2.begin(), c2.end(), &double_packed);
result += std::islower(double_packed) ? (double_packed - 'a' + 1) : (double_packed - 'A' + 27);
if (std::cin.eof())
break;
}
fmt::print("Result: {}\n", result);
}