Day6
This commit is contained in:
parent
43448aaeb6
commit
b922c94b43
6 changed files with 273 additions and 5 deletions
|
|
@ -37,12 +37,12 @@ static auto parseInput(const std::string &filename) -> std::expected<PuzzleInput
|
|||
std::string puzzleLine{};
|
||||
while (std::getline(inputF, puzzleLine)) {
|
||||
if (puzzleLine.empty()) {
|
||||
std::println("Empty string");
|
||||
// std::println("Empty string");
|
||||
break;
|
||||
}
|
||||
auto subParts = std::ranges::to<std::vector<std::string>>(std::views::split(puzzleLine, '-'));
|
||||
puzzleInput.freshRanges.emplace_back(std::stoll(subParts[0]), std::stoll(subParts[1]));
|
||||
std::println("Range: {}", subParts);
|
||||
// std::println("Range: {}", subParts);
|
||||
}
|
||||
|
||||
while (std::getline(inputF, puzzleLine)) {
|
||||
|
|
@ -79,7 +79,7 @@ static long long countAll(const std::ranges::range auto &ranges) {
|
|||
|
||||
long long bigNum{};
|
||||
for (const auto &range : ranges) {
|
||||
std::println("{}:{}", range.first, range.second);
|
||||
// std::println("{}:{}", range.first, range.second);
|
||||
if (range == FreshRange(-1, -1)) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -96,14 +96,14 @@ static auto countFreshIngredientsRange(std::vector<FreshRange> &ranges) -> long
|
|||
auto cur = rangeList.begin();
|
||||
while (true) {
|
||||
auto next = std::next(cur);
|
||||
std::println("Starting with {}", *cur);
|
||||
// std::println("Starting with {}", *cur);
|
||||
|
||||
if (next == rangeList.end()) { // No need to compare against the end
|
||||
break;
|
||||
}
|
||||
|
||||
if (cur->second >= next->first) {
|
||||
std::println("\t Merging! {}", *next);
|
||||
// std::println("\t Merging! {}", *next);
|
||||
cur->second = std::max(cur->second, next->second);
|
||||
|
||||
rangeList.erase(next);
|
||||
|
|
@ -140,5 +140,16 @@ auto main() -> int {
|
|||
std::print("{}\n", realPuzzle.error());
|
||||
}
|
||||
|
||||
auto tianyi = parseInput("tianyi_input");
|
||||
if (tianyi) {
|
||||
// auto realResult = countFreshIngredients(*realPuzzle);
|
||||
// std::println("P1 Real result: {}", realResult);
|
||||
|
||||
auto tianyir = countFreshIngredientsRange((*tianyi).freshRanges);
|
||||
std::println("Tianyi result: {}", tianyir);
|
||||
} else {
|
||||
std::print("{}\n", realPuzzle.error());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue