Compare commits
No commits in common. 'dcee17005f61a1ecf78f8e8cc85f371deeca047d' and 'a757a50b6ceee6b07f9e9358fb714f6e3321bc04' have entirely different histories.
dcee17005f
...
a757a50b6c
5 changed files with 5 additions and 53 deletions
@ -1,46 +1,9 @@ |
|||||||
#include "Day02.h" |
#include "Day02.h" |
||||||
|
|
||||||
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; |
|
||||||
} |
|
||||||
|
|
||||||
Result Day02::Task1() { |
Result Day02::Task1() { |
||||||
int score = 0; |
return Day::Task1(); |
||||||
for (string line : input){ |
|
||||||
char predict = line.at(0); |
|
||||||
char answer = char(line.at(2) - 23); |
|
||||||
score += getScore(predict, answer); |
|
||||||
} |
|
||||||
return to_string(score); |
|
||||||
} |
} |
||||||
|
|
||||||
Result Day02::Task2() { |
Result Day02::Task2() { |
||||||
int score = 0; |
return Day::Task2(); |
||||||
for (string line : input){ |
|
||||||
char predict = line.at(0); |
|
||||||
char outcome = line.at(2); |
|
||||||
|
|
||||||
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'; |
|
||||||
} |
|
||||||
|
|
||||||
score += getScore(predict, answer); |
|
||||||
} |
|
||||||
return to_string(score); |
|
||||||
} |
} |
Loading…
Reference in new issue