Tidy solution for 2022 day 15 part 2.

This commit is contained in:
2022-12-15 09:46:52 +00:00
parent 026f2eba2c
commit ed02811d56

View File

@@ -49,10 +49,6 @@ auto main() -> int
} }
for (Int row{0}; row < max_row; ++row) { for (Int row{0}; row < max_row; ++row) {
if (row % 100'000 == 0) {
std::cout << " Row: " << row << "\n";
std::flush(std::cout);
}
std::set<Range, RangeCompare> ranges; std::set<Range, RangeCompare> ranges;
for (auto const& sensor : sensors) { for (auto const& sensor : sensors) {
@@ -74,36 +70,19 @@ auto main() -> int
} }
Int last_pos{0}; Int last_pos{0};
UInt count{0};
for (auto const& r : ranges) { for (auto const& r : ranges) {
assert(r.first < r.second); assert(r.first < r.second);
if (r.second < last_pos) { if (r.second < last_pos) {
continue; continue;
} }
auto b{std::max(r.first, last_pos)}; if (r.first > last_pos) {
auto e{std::min(r.second, max_row)}; std::cout << " Gap in " << last_pos << " - " << r.first << "\n";
count += (e - b); std::cout << "Score = " << last_pos * 4000000 + row << "\n";
last_pos = e;
}
if (count != max_row) {
std::cout << "Row interested in: " << row << "\n";
std::cout << "Count = " << count << "\n";
Int gap{0};
for (auto const& r : ranges) {
assert(r.first < r.second);
if (r.second < gap) {
continue;
}
if (r.first > gap) {
std::cout << " Gap in " << gap << " - " << r.first << "\n";
std::cout << "Score = " << gap * 4000000 + row << "\n";
}
gap = std::min(r.second, max_row);
}
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
}
last_pos = std::min(r.second, max_row);
}
}
return EXIT_FAILURE; return EXIT_FAILURE;
} }