Make Grid iterable

This commit is contained in:
2024-09-05 20:10:34 -07:00
parent 9e6223f886
commit d6fc0396cb
11 changed files with 77 additions and 46 deletions

View File

@@ -17,13 +17,13 @@ auto Part1(aocpp::Grid const &input, std::int64_t reps = 10'000) -> std::int64_t
std::unordered_set<aocpp::Coord> infected;
// Initialize set of infected locations
input.each([&infected](auto const pos, auto const cell)
for (auto [pos, cell] : input)
{
if (cell == '#')
{
infected.insert(pos);
}
});
}
// Start in the middle
aocpp::Coord pos;
@@ -62,13 +62,13 @@ auto Part2(aocpp::Grid const &input, std::int64_t reps = 10'000'000) -> std::int
std::unordered_map<aocpp::Coord, char> cells;
// Initialize set of infected locations
input.each([&cells](auto const pos, auto const cell)
for (auto [pos, cell] : input)
{
if (cell == '#')
{
cells.try_emplace(pos, '#');
}
});
}
// Start in the middle
aocpp::Coord pos;