better setup

master
Benjamin Kraft 3 years ago
parent db9d8ff593
commit a8c68d640b
  1. 2
      src/01/Day01.h
  2. 2
      src/02/Day02.h
  3. 2
      src/03/Day03.h
  4. 12
      src/Day.h
  5. 22
      src/days.h
  6. 15
      src/main.cpp
  7. 11
      src/util.h

@ -8,8 +8,6 @@ class Day01 : public Day {
protected: protected:
Result Task1() override; Result Task1() override;
Result Task2() override; Result Task2() override;
public:
explicit Day01(Input &input) : Day(input) {}
}; };

@ -8,8 +8,6 @@ class Day02 : public Day {
protected: protected:
Result Task1() override; Result Task1() override;
Result Task2() override; Result Task2() override;
public:
explicit Day02(Input &input) : Day(input) {}
}; };

@ -8,8 +8,6 @@ class Day03 : public Day {
protected: protected:
Result Task1() override; Result Task1() override;
Result Task2() override; Result Task2() override;
public:
explicit Day03(Input &input) : Day(input) {}
}; };

@ -1,11 +1,8 @@
#ifndef ADVENTOFCODE2022_DAY_H #ifndef ADVENTOFCODE2022_DAY_H
#define ADVENTOFCODE2022_DAY_H #define ADVENTOFCODE2022_DAY_H
#include <vector> #include "util.h"
#include <string>
#include <tuple>
#include <chrono> #include <chrono>
#include <iostream>
using namespace std::chrono; using namespace std::chrono;
typedef std::string Result; typedef std::string Result;
@ -17,8 +14,11 @@ protected:
virtual Result Task1() { return ""; } virtual Result Task1() { return ""; }
virtual Result Task2() { return ""; } virtual Result Task2() { return ""; }
public: public:
explicit Day(Input &input) : input(input) {} explicit Day() = default;
int run() { ~Day() = default;
int run(Input &_input) {
this->input = _input;
auto start = high_resolution_clock::now(); auto start = high_resolution_clock::now();
std::cout << "Task 1" << std::endl; std::cout << "Task 1" << std::endl;

@ -6,22 +6,12 @@
#include "02/Day02.h" #include "02/Day02.h"
#include "03/Day03.h" #include "03/Day03.h"
Day* getDay(int dayNum, std::vector<std::string> &input){ std::vector<Day*> getAllDays(){
Day* day; return std::vector<Day*> {
switch (dayNum){ new Day01(),
case 1: new Day02(),
day = new Day01(input); new Day03()
break; };
case 2:
day = new Day02(input);
break;
case 3:
day = new Day03(input);
break;
default:
day = nullptr;
}
return day;
} }
#endif #endif

@ -46,24 +46,23 @@ std::string getSessionKey(){
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
std::string key = getSessionKey(); auto key = getSessionKey();
bool useTestInput = false; bool useTestInput = false;
auto days = getAllDays();
for (int i = 1; i < argc; i++){ for (int i = 1; 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;
auto input = getInput(dayNum, key, useTestInput); auto input = getInput(dayNum, key, useTestInput);
auto day = getDay(dayNum, input); auto day = days[dayNum - 1];
if (day == nullptr){ int code = day->run(input);
std::cout << "Could not run day " << dayNum << std::endl;
continue;
}
int code = day->run();
if (code != 0) if (code != 0)
return code; return code;
} }
for (Day* day : days)
delete day;
return 0; return 0;
} }

@ -0,0 +1,11 @@
#ifndef ADVENTOFCODE2022_UTIL_H
#define ADVENTOFCODE2022_UTIL_H
#include <vector>
#include <numeric>
#include <string>
#include <tuple>
#include <iostream>
#endif
Loading…
Cancel
Save