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:
Result Task1() override;
Result Task2() override;
public:
explicit Day01(Input &input) : Day(input) {}
};

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

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

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

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

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