-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from EduardGomezEscandell/load-file
Rename solvebase and implement load()
- Loading branch information
Showing
12 changed files
with
108 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
1abc2 | ||
pqr3stu8vwx | ||
a1b2c3d4e5f | ||
treb7uchet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
1abc2 | ||
pqr3stu8vwx | ||
a1b2c3d4e5f | ||
treb7uchet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
#include "day01.hpp" | ||
#include <iostream> | ||
|
||
std::int64_t Day01::part1() { return 1; } | ||
std::int64_t Day01::part1() { | ||
std::cout << this->input << std::endl; | ||
return 1; | ||
} | ||
|
||
std::int64_t Day01::part2() { return 2; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "solution.hpp" | ||
|
||
#include <format> | ||
#include <fstream> | ||
#include <iostream> | ||
#include <sstream> | ||
#include <stdexcept> | ||
|
||
namespace xmas { | ||
|
||
void solution::run() { | ||
std::cout << "Day 1" << std::endl; | ||
try { | ||
const auto p1 = this->part1(); | ||
std::cout << " Result 1: " << p1 << '\n'; | ||
} catch (std::runtime_error &err) { | ||
std::cerr << "Part 1 failed with message: " << err.what() << std::endl; | ||
} | ||
|
||
try { | ||
const auto p2 = this->part2(); | ||
std::cout << " Result 2: " << p2 << '\n'; | ||
} catch (std::runtime_error &err) { | ||
std::cerr << "Part 2 failed with message: " << err.what() << std::endl; | ||
} | ||
} | ||
|
||
void solution::load(std::string_view path) { | ||
std::ifstream f(path.data()); | ||
std::stringstream buff; | ||
buff << f.rdbuf(); | ||
input = std::move(buff).str(); | ||
|
||
if (input.size() == 0) { | ||
throw std::runtime_error( | ||
std::format("did not load any data from {}", path)); | ||
} | ||
} | ||
|
||
} // namespace xmas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <optional> | ||
#include <stdexcept> | ||
|
||
namespace xmas { | ||
|
||
class solution { | ||
public: | ||
virtual int day() = 0; | ||
|
||
virtual void run(); | ||
virtual void load(std::string_view path); | ||
|
||
protected: | ||
virtual std::int64_t part1() { throw std::runtime_error("not implemented"); } | ||
virtual std::int64_t part2() { throw std::runtime_error("not implemented"); } | ||
|
||
std::string input; | ||
|
||
private: | ||
std::optional<std::int64_t> p1; | ||
std::optional<std::int64_t> p2; | ||
}; | ||
|
||
} // namespace xmas |
This file was deleted.
Oops, something went wrong.