Compare commits

..

No commits in common. 'dcee17005f61a1ecf78f8e8cc85f371deeca047d' and 'a757a50b6ceee6b07f9e9358fb714f6e3321bc04' have entirely different histories.

  1. 4
      README.md
  2. 41
      src/days/02/Day02.cpp
  3. 3
      src/days/02/Day02.h
  4. 7
      src/main.cpp
  5. 3
      src/util.h

@ -9,6 +9,4 @@ Place a file called "session" with your session key cookie from https://adventof
Expects runtime arguments as days, for example: Expects runtime arguments as days, for example:
"5 9 1" executes Days 5, 9, 1 in this order. "5 9 1" executes Days 5, 9, 1 in this order.
Add argument "T" before to use XX_testInput.txt rather than XX_input.txt

@ -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);
} }

@ -7,7 +7,4 @@ protected:
Result Task1() override; Result Task1() override;
Result Task2() override; Result Task2() override;
private:
// chars A, B, C
static int getScore(char, char);
}; };

@ -50,12 +50,7 @@ int main(int argc, char *argv[]) {
auto days = getAllDays(); auto days = getAllDays();
std::filesystem::create_directory("input"); std::filesystem::create_directory("input");
int i = 1; for (int i = 1; i < argc; i++) {
if (argc > 1 && std::string(argv[1]) == "T") {
useTestInput = true;
i++;
}
for (; i < argc; i++) {
int dayNum = std::stoi(argv[i]); int dayNum = std::stoi(argv[i]);
std::cout << "Running day " << dayNum << std::endl; std::cout << "Running day " << dayNum << std::endl;
Input input = getInput(dayNum, key, useTestInput); Input input = getInput(dayNum, key, useTestInput);

@ -7,5 +7,4 @@
#include <iostream> #include <iostream>
using std::stoi, std::to_string; using std::stoi, std::to_string;
using std::cout, std::endl; using std::cout, std::endl;
using std::string, std::vector;
Loading…
Cancel
Save