Advent of Code 2022 - 2nd attempt in c++
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

47 lines
1.0 KiB

#include <iostream>
#include <vector>
#include <array>
using namespace std;
vector<array<unsigned, 2>> parse()
{
vector<array<unsigned, 2>> input;
for (string line; getline(cin, line);) {
if (line.at(1) != ' ') throw "parse";
unsigned oppo = line.at(0) - 'A';
unsigned user = line.at(2) - 'X';
if (oppo >= 3 || user >= 3) throw "parse";
input.push_back({oppo, user});
}
return input;
}
unsigned p1(vector<array<unsigned, 2>> &input)
{
unsigned score = 0;
for (auto i : input) {
unsigned shape = i[1];
unsigned outcome = (i[1] - i[0] + 4) % 3;
score += shape + 1 + outcome * 3;
}
return score;
}
unsigned p2(vector<array<unsigned, 2>> &input)
{
unsigned score = 0;
for (auto i : input) {
unsigned shape = (i[1] + i[0] + 2) % 3;
unsigned outcome = i[1];
score += shape + 1 + outcome * 3;
}
return score;
}
int main()
{
auto input = parse();
cout << p1(input) << endl;
cout << p2(input) << endl;
}