Make Grid iterable
This commit is contained in:
@@ -22,7 +22,7 @@ Dir directions[4] {Up, Down, Left, Right};
|
||||
auto Part1(Grid const& grid) -> std::int64_t
|
||||
{
|
||||
std::int64_t result {0};
|
||||
grid.each([&](Coord const c, char const v) {
|
||||
for (auto [c, v] : grid) {
|
||||
result += std::any_of(
|
||||
std::begin(directions), std::end(directions),
|
||||
[&](Dir const dir) {
|
||||
@@ -31,14 +31,14 @@ auto Part1(Grid const& grid) -> std::int64_t
|
||||
}
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
auto Part2(Grid const& grid) -> std::int64_t
|
||||
{
|
||||
std::int64_t result {0};
|
||||
grid.each([&](Coord const c, char const v) {
|
||||
for (auto [c, v] : grid) {
|
||||
auto score = std::transform_reduce(
|
||||
std::begin(directions), std::end(directions),
|
||||
std::int64_t{1}, std::multiplies(), // product
|
||||
@@ -51,7 +51,7 @@ auto Part2(Grid const& grid) -> std::int64_t
|
||||
return count;
|
||||
});
|
||||
if (result < score) result = score;
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@@ -27,13 +27,13 @@ auto Parse(std::istream & in) -> std::tuple<Coord, std::vector<Coord>, Coord, Gr
|
||||
auto& end = std::get<2>(result);
|
||||
auto& grid = std::get<3>(result);
|
||||
|
||||
grid.each([&](Coord c, char v) {
|
||||
for (auto [c, v] : grid) {
|
||||
switch (v) {
|
||||
case 'S': grid[c] = 'a'; start1 = c; break;
|
||||
case 'E': grid[c] = 'z'; end = c; break;
|
||||
case 'a': starts2.push_back(c); break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
Reference in New Issue
Block a user