even better setup

master
Benjamin Kraft 3 years ago
parent 2e133c698b
commit 89b1cea36a
  1. 17
      fill.py
  2. 10
      pre.cpp
  3. 14
      pre.h
  4. 6
      src/Day.h
  5. 17
      src/days.h
  6. 0
      src/days/01/Day01.cpp
  7. 2
      src/days/01/Day01.h
  8. 0
      src/days/02/Day02.cpp
  9. 2
      src/days/02/Day02.h
  10. 0
      src/days/03/Day03.cpp
  11. 2
      src/days/03/Day03.h
  12. 10
      src/days/04/Day04.cpp
  13. 14
      src/days/04/Day04.h
  14. 10
      src/days/05/Day05.cpp
  15. 14
      src/days/05/Day05.h
  16. 10
      src/days/06/Day06.cpp
  17. 14
      src/days/06/Day06.h
  18. 10
      src/days/07/Day07.cpp
  19. 14
      src/days/07/Day07.h
  20. 10
      src/days/08/Day08.cpp
  21. 14
      src/days/08/Day08.h
  22. 10
      src/days/09/Day09.cpp
  23. 14
      src/days/09/Day09.h
  24. 10
      src/days/10/Day10.cpp
  25. 14
      src/days/10/Day10.h
  26. 10
      src/days/11/Day11.cpp
  27. 14
      src/days/11/Day11.h
  28. 10
      src/days/12/Day12.cpp
  29. 14
      src/days/12/Day12.h
  30. 10
      src/days/13/Day13.cpp
  31. 14
      src/days/13/Day13.h
  32. 10
      src/days/14/Day14.cpp
  33. 14
      src/days/14/Day14.h
  34. 10
      src/days/15/Day15.cpp
  35. 14
      src/days/15/Day15.h
  36. 10
      src/days/16/Day16.cpp
  37. 14
      src/days/16/Day16.h
  38. 10
      src/days/17/Day17.cpp
  39. 14
      src/days/17/Day17.h
  40. 10
      src/days/18/Day18.cpp
  41. 14
      src/days/18/Day18.h
  42. 10
      src/days/19/Day19.cpp
  43. 14
      src/days/19/Day19.h
  44. 10
      src/days/20/Day20.cpp
  45. 14
      src/days/20/Day20.h
  46. 10
      src/days/21/Day21.cpp
  47. 14
      src/days/21/Day21.h
  48. 10
      src/days/22/Day22.cpp
  49. 14
      src/days/22/Day22.h
  50. 10
      src/days/23/Day23.cpp
  51. 14
      src/days/23/Day23.h
  52. 10
      src/days/24/Day24.cpp
  53. 14
      src/days/24/Day24.h
  54. 10
      src/days/25/Day25.cpp
  55. 14
      src/days/25/Day25.h
  56. 61
      src/days/days.h
  57. 7
      src/main.cpp

@ -0,0 +1,17 @@
import os
preH = open("pre.h", "r").read()
preCpp = open("pre.cpp", "r").read()
for dayNum in range(1, 26):
pad = f'{dayNum:02}'
dirName = f"src/days/{pad}"
try:
os.mkdir(dirName)
except OSError:
continue
with open(f"{dirName}/Day{pad}.h", "w") as file:
file.write(preH.replace("XX", pad))
with open(f"{dirName}/Day{pad}.cpp", "w") as file:
file.write(preCpp.replace("XX", pad))

@ -0,0 +1,10 @@
#include "DayXX.h"
Result DayXX::Task1() {
return Day::Task1();
}
Result DayXX::Task2() {
return Day::Task2();
}

14
pre.h

@ -0,0 +1,14 @@
#ifndef ADVENTOFCODE2022_DAYXX_H
#define ADVENTOFCODE2022_DAYXX_H
#include "../../Day.h"
class DayXX : public Day {
protected:
Result Task1() override;
Result Task2() override;
};
#endif

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

@ -1,17 +0,0 @@
#ifndef ADVENTOFCODE2022_DAYS_H
#define ADVENTOFCODE2022_DAYS_H
#include "01/Day01.h"
#include "02/Day02.h"
#include "03/Day03.h"
std::vector<Day*> getAllDays(){
return std::vector<Day*> {
new Day01(),
new Day02(),
new Day03()
};
}
#endif

@ -2,7 +2,7 @@
#ifndef ADVENTOFCODE2022_DAY01_H #ifndef ADVENTOFCODE2022_DAY01_H
#define ADVENTOFCODE2022_DAY01_H #define ADVENTOFCODE2022_DAY01_H
#include "../Day.h" #include "../../Day.h"
class Day01 : public Day { class Day01 : public Day {
protected: protected:

@ -2,7 +2,7 @@
#ifndef ADVENTOFCODE2022_DAY02_H #ifndef ADVENTOFCODE2022_DAY02_H
#define ADVENTOFCODE2022_DAY02_H #define ADVENTOFCODE2022_DAY02_H
#include "../Day.h" #include "../../Day.h"
class Day02 : public Day { class Day02 : public Day {
protected: protected:

@ -2,7 +2,7 @@
#ifndef ADVENTOFCODE2022_DAY03_H #ifndef ADVENTOFCODE2022_DAY03_H
#define ADVENTOFCODE2022_DAY03_H #define ADVENTOFCODE2022_DAY03_H
#include "../Day.h" #include "../../Day.h"
class Day03 : public Day { class Day03 : public Day {
protected: protected:

@ -0,0 +1,10 @@
#include "Day04.h"
Result Day04::Task1() {
return Day::Task1();
}
Result Day04::Task2() {
return Day::Task2();
}

@ -0,0 +1,14 @@
#ifndef ADVENTOFCODE2022_DAY04_H
#define ADVENTOFCODE2022_DAY04_H
#include "../../Day.h"
class Day04 : public Day {
protected:
Result Task1() override;
Result Task2() override;
};
#endif

@ -0,0 +1,10 @@
#include "Day05.h"
Result Day05::Task1() {
return Day::Task1();
}
Result Day05::Task2() {
return Day::Task2();
}

@ -0,0 +1,14 @@
#ifndef ADVENTOFCODE2022_DAY05_H
#define ADVENTOFCODE2022_DAY05_H
#include "../../Day.h"
class Day05 : public Day {
protected:
Result Task1() override;
Result Task2() override;
};
#endif

@ -0,0 +1,10 @@
#include "Day06.h"
Result Day06::Task1() {
return Day::Task1();
}
Result Day06::Task2() {
return Day::Task2();
}

@ -0,0 +1,14 @@
#ifndef ADVENTOFCODE2022_DAY06_H
#define ADVENTOFCODE2022_DAY06_H
#include "../../Day.h"
class Day06 : public Day {
protected:
Result Task1() override;
Result Task2() override;
};
#endif

@ -0,0 +1,10 @@
#include "Day07.h"
Result Day07::Task1() {
return Day::Task1();
}
Result Day07::Task2() {
return Day::Task2();
}

@ -0,0 +1,14 @@
#ifndef ADVENTOFCODE2022_DAY07_H
#define ADVENTOFCODE2022_DAY07_H
#include "../../Day.h"
class Day07 : public Day {
protected:
Result Task1() override;
Result Task2() override;
};
#endif

@ -0,0 +1,10 @@
#include "Day08.h"
Result Day08::Task1() {
return Day::Task1();
}
Result Day08::Task2() {
return Day::Task2();
}

@ -0,0 +1,14 @@
#ifndef ADVENTOFCODE2022_DAY08_H
#define ADVENTOFCODE2022_DAY08_H
#include "../../Day.h"
class Day08 : public Day {
protected:
Result Task1() override;
Result Task2() override;
};
#endif

@ -0,0 +1,10 @@
#include "Day09.h"
Result Day09::Task1() {
return Day::Task1();
}
Result Day09::Task2() {
return Day::Task2();
}

@ -0,0 +1,14 @@
#ifndef ADVENTOFCODE2022_DAY09_H
#define ADVENTOFCODE2022_DAY09_H
#include "../../Day.h"
class Day09 : public Day {
protected:
Result Task1() override;
Result Task2() override;
};
#endif

@ -0,0 +1,10 @@
#include "Day10.h"
Result Day10::Task1() {
return Day::Task1();
}
Result Day10::Task2() {
return Day::Task2();
}

@ -0,0 +1,14 @@
#ifndef ADVENTOFCODE2022_DAY10_H
#define ADVENTOFCODE2022_DAY10_H
#include "../../Day.h"
class Day10 : public Day {
protected:
Result Task1() override;
Result Task2() override;
};
#endif

@ -0,0 +1,10 @@
#include "Day11.h"
Result Day11::Task1() {
return Day::Task1();
}
Result Day11::Task2() {
return Day::Task2();
}

@ -0,0 +1,14 @@
#ifndef ADVENTOFCODE2022_DAY11_H
#define ADVENTOFCODE2022_DAY11_H
#include "../../Day.h"
class Day11 : public Day {
protected:
Result Task1() override;
Result Task2() override;
};
#endif

@ -0,0 +1,10 @@
#include "Day12.h"
Result Day12::Task1() {
return Day::Task1();
}
Result Day12::Task2() {
return Day::Task2();
}

@ -0,0 +1,14 @@
#ifndef ADVENTOFCODE2022_DAY12_H
#define ADVENTOFCODE2022_DAY12_H
#include "../../Day.h"
class Day12 : public Day {
protected:
Result Task1() override;
Result Task2() override;
};
#endif

@ -0,0 +1,10 @@
#include "Day13.h"
Result Day13::Task1() {
return Day::Task1();
}
Result Day13::Task2() {
return Day::Task2();
}

@ -0,0 +1,14 @@
#ifndef ADVENTOFCODE2022_DAY13_H
#define ADVENTOFCODE2022_DAY13_H
#include "../../Day.h"
class Day13 : public Day {
protected:
Result Task1() override;
Result Task2() override;
};
#endif

@ -0,0 +1,10 @@
#include "Day14.h"
Result Day14::Task1() {
return Day::Task1();
}
Result Day14::Task2() {
return Day::Task2();
}

@ -0,0 +1,14 @@
#ifndef ADVENTOFCODE2022_DAY14_H
#define ADVENTOFCODE2022_DAY14_H
#include "../../Day.h"
class Day14 : public Day {
protected:
Result Task1() override;
Result Task2() override;
};
#endif

@ -0,0 +1,10 @@
#include "Day15.h"
Result Day15::Task1() {
return Day::Task1();
}
Result Day15::Task2() {
return Day::Task2();
}

@ -0,0 +1,14 @@
#ifndef ADVENTOFCODE2022_DAY15_H
#define ADVENTOFCODE2022_DAY15_H
#include "../../Day.h"
class Day15 : public Day {
protected:
Result Task1() override;
Result Task2() override;
};
#endif

@ -0,0 +1,10 @@
#include "Day16.h"
Result Day16::Task1() {
return Day::Task1();
}
Result Day16::Task2() {
return Day::Task2();
}

@ -0,0 +1,14 @@
#ifndef ADVENTOFCODE2022_DAY16_H
#define ADVENTOFCODE2022_DAY16_H
#include "../../Day.h"
class Day16 : public Day {
protected:
Result Task1() override;
Result Task2() override;
};
#endif

@ -0,0 +1,10 @@
#include "Day17.h"
Result Day17::Task1() {
return Day::Task1();
}
Result Day17::Task2() {
return Day::Task2();
}

@ -0,0 +1,14 @@
#ifndef ADVENTOFCODE2022_DAY17_H
#define ADVENTOFCODE2022_DAY17_H
#include "../../Day.h"
class Day17 : public Day {
protected:
Result Task1() override;
Result Task2() override;
};
#endif

@ -0,0 +1,10 @@
#include "Day18.h"
Result Day18::Task1() {
return Day::Task1();
}
Result Day18::Task2() {
return Day::Task2();
}

@ -0,0 +1,14 @@
#ifndef ADVENTOFCODE2022_DAY18_H
#define ADVENTOFCODE2022_DAY18_H
#include "../../Day.h"
class Day18 : public Day {
protected:
Result Task1() override;
Result Task2() override;
};
#endif

@ -0,0 +1,10 @@
#include "Day19.h"
Result Day19::Task1() {
return Day::Task1();
}
Result Day19::Task2() {
return Day::Task2();
}

@ -0,0 +1,14 @@
#ifndef ADVENTOFCODE2022_DAY19_H
#define ADVENTOFCODE2022_DAY19_H
#include "../../Day.h"
class Day19 : public Day {
protected:
Result Task1() override;
Result Task2() override;
};
#endif

@ -0,0 +1,10 @@
#include "Day20.h"
Result Day20::Task1() {
return Day::Task1();
}
Result Day20::Task2() {
return Day::Task2();
}

@ -0,0 +1,14 @@
#ifndef ADVENTOFCODE2022_DAY20_H
#define ADVENTOFCODE2022_DAY20_H
#include "../../Day.h"
class Day20 : public Day {
protected:
Result Task1() override;
Result Task2() override;
};
#endif

@ -0,0 +1,10 @@
#include "Day21.h"
Result Day21::Task1() {
return Day::Task1();
}
Result Day21::Task2() {
return Day::Task2();
}

@ -0,0 +1,14 @@
#ifndef ADVENTOFCODE2022_DAY21_H
#define ADVENTOFCODE2022_DAY21_H
#include "../../Day.h"
class Day21 : public Day {
protected:
Result Task1() override;
Result Task2() override;
};
#endif

@ -0,0 +1,10 @@
#include "Day22.h"
Result Day22::Task1() {
return Day::Task1();
}
Result Day22::Task2() {
return Day::Task2();
}

@ -0,0 +1,14 @@
#ifndef ADVENTOFCODE2022_DAY22_H
#define ADVENTOFCODE2022_DAY22_H
#include "../../Day.h"
class Day22 : public Day {
protected:
Result Task1() override;
Result Task2() override;
};
#endif

@ -0,0 +1,10 @@
#include "Day23.h"
Result Day23::Task1() {
return Day::Task1();
}
Result Day23::Task2() {
return Day::Task2();
}

@ -0,0 +1,14 @@
#ifndef ADVENTOFCODE2022_DAY23_H
#define ADVENTOFCODE2022_DAY23_H
#include "../../Day.h"
class Day23 : public Day {
protected:
Result Task1() override;
Result Task2() override;
};
#endif

@ -0,0 +1,10 @@
#include "Day24.h"
Result Day24::Task1() {
return Day::Task1();
}
Result Day24::Task2() {
return Day::Task2();
}

@ -0,0 +1,14 @@
#ifndef ADVENTOFCODE2022_DAY24_H
#define ADVENTOFCODE2022_DAY24_H
#include "../../Day.h"
class Day24 : public Day {
protected:
Result Task1() override;
Result Task2() override;
};
#endif

@ -0,0 +1,10 @@
#include "Day25.h"
Result Day25::Task1() {
return Day::Task1();
}
Result Day25::Task2() {
return Day::Task2();
}

@ -0,0 +1,14 @@
#ifndef ADVENTOFCODE2022_DAY25_H
#define ADVENTOFCODE2022_DAY25_H
#include "../../Day.h"
class Day25 : public Day {
protected:
Result Task1() override;
Result Task2() override;
};
#endif

@ -0,0 +1,61 @@
#ifndef ADVENTOFCODE2022_DAYS_H
#define ADVENTOFCODE2022_DAYS_H
#include "01/Day01.h"
#include "02/Day02.h"
#include "03/Day03.h"
#include "04/Day04.h"
#include "05/Day05.h"
#include "06/Day06.h"
#include "07/Day07.h"
#include "08/Day08.h"
#include "09/Day09.h"
#include "10/Day10.h"
#include "11/Day11.h"
#include "12/Day12.h"
#include "13/Day13.h"
#include "14/Day14.h"
#include "15/Day15.h"
#include "16/Day16.h"
#include "17/Day17.h"
#include "18/Day18.h"
#include "19/Day19.h"
#include "20/Day20.h"
#include "21/Day21.h"
#include "22/Day22.h"
#include "23/Day23.h"
#include "24/Day24.h"
#include "25/Day25.h"
std::vector<Day*> getAllDays(){
return {
new Day01(),
new Day02(),
new Day03(),
new Day04(),
new Day05(),
new Day06(),
new Day07(),
new Day08(),
new Day09(),
new Day10(),
new Day11(),
new Day12(),
new Day13(),
new Day14(),
new Day15(),
new Day16(),
new Day17(),
new Day18(),
new Day19(),
new Day20(),
new Day21(),
new Day22(),
new Day23(),
new Day24(),
new Day25()
};
}
#endif

@ -1,8 +1,7 @@
#include <filesystem> #include <filesystem>
#include "days.h"
#include <cpr/cpr.h> #include <cpr/cpr.h>
#include "days/days.h"
using namespace std::chrono;
std::vector<std::string> getInput(int day, std::string key, bool useTestInput){ std::vector<std::string> getInput(int day, std::string key, bool useTestInput){
std::vector<std::string> result; std::vector<std::string> result;
@ -54,8 +53,8 @@ int main(int argc, char *argv[]) {
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); Input input = getInput(dayNum, key, useTestInput);
auto day = days[dayNum - 1]; Day* day = days[dayNum - 1];
int code = day->run(input); int code = day->run(input);
if (code != 0) if (code != 0)
return code; return code;

Loading…
Cancel
Save