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.

46 lines
900 B

#include "Day02.h"
2 years ago
int Day02::getScore(char opponent, char me) {
int outcome;
if (opponent == me)
outcome = 3;
else if (opponent == me + 1 || opponent == me - 2)
outcome = 0;
else
outcome = 6;
return outcome + me - 64;
2 years ago
}
3 years ago
Result Day02::Task1() {
int score = 0;
for (string line: input) {
char predict = line.at(0);
char answer = char(line.at(2) - 23);
score += getScore(predict, answer);
}
return to_string(score);
}
3 years ago
Result Day02::Task2() {
int score = 0;
for (string line: input) {
char predict = line.at(0);
char outcome = line.at(2);
2 years ago
char answer;
if (outcome == 'X') {
if (predict > 'A') answer = char(predict - 1);
else answer = 'C';
}
if (outcome == 'Y') {
answer = predict;
}
if (outcome == 'Z') {
if (predict < 'C') answer = char(predict + 1);
else answer = 'A';
}
2 years ago
score += getScore(predict, answer);
}
return to_string(score);
3 years ago
}