Line data Source code
1 : #pragma once
2 :
3 : #include <chrono>
4 : #include <filesystem>
5 : #include <string>
6 : #include <string_view>
7 : #include <vector>
8 :
9 : class Puzzle {
10 : public:
11 : using Day = std::chrono::day;
12 : using Year = std::chrono::year;
13 :
14 : Puzzle(Year const year_, Day const day_, std::filesystem::path inputFile)
15 9045 : : _year(year_), _day(day_), _inputFile(std::move(inputFile)) {}
16 :
17 9045 : virtual ~Puzzle() = default;
18 :
19 9045 : [[nodiscard]] Year year() const { return _year; }
20 9045 : [[nodiscard]] Day day() const { return _day; }
21 : [[nodiscard]] std::string const name() const;
22 134 : [[nodiscard]] std::filesystem::path const &inputFile() const { return _inputFile; }
23 :
24 : virtual std::string runPart1(std::string_view const input) const = 0; // NOLINT
25 : virtual std::string runPart2(std::string_view const input) const = 0; // NOLINT
26 :
27 : [[nodiscard]] virtual std::string_view solutionPart1() const = 0;
28 : [[nodiscard]] virtual std::string_view solutionPart2() const = 0;
29 :
30 : [[nodiscard]] static Year latestYear();
31 : [[nodiscard]] static Day latestDay(Year const year);
32 : [[nodiscard]] static std::unique_ptr<Puzzle> create(Year const year, Day const day);
33 0 : [[nodiscard]] static std::unique_ptr<Puzzle> create(Day const day) {
34 0 : return create(latestYear(), day);
35 0 : };
36 0 : [[nodiscard]] static std::unique_ptr<Puzzle> createLatest() {
37 0 : return create(latestDay(latestYear()));
38 0 : };
39 : [[nodiscard]] static std::vector<std::unique_ptr<Puzzle>> createAll();
40 : [[nodiscard]] static std::vector<std::unique_ptr<Puzzle>> createAll(Year const year);
41 0 : [[nodiscard]] static std::vector<std::unique_ptr<Puzzle>> createAllLatestYear() {
42 0 : return createAll(latestYear());
43 0 : };
44 :
45 : private:
46 : Year _year;
47 : Day _day;
48 : std::filesystem::path _inputFile;
49 : };
|