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.

50 lines
1007 B

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