aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--2023/src/day21.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/2023/src/day21.cpp b/2023/src/day21.cpp
index 21a45f7..88fafec 100644
--- a/2023/src/day21.cpp
+++ b/2023/src/day21.cpp
@@ -38,6 +38,9 @@ find_neighbours(position pos, const vector<string>& lines)
38{ 38{
39 static const vector<position> movements = { { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 } }; 39 static const vector<position> movements = { { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 } };
40 40
41 const auto height = lines.size();
42 const auto width = lines[0].size();
43
41 set<position> neighbours; 44 set<position> neighbours;
42 const auto [row, col] = pos; 45 const auto [row, col] = pos;
43 46
@@ -45,7 +48,7 @@ find_neighbours(position pos, const vector<string>& lines)
45 const auto nrow = row + drow; 48 const auto nrow = row + drow;
46 const auto ncol = col + dcol; 49 const auto ncol = col + dcol;
47 50
48 if ( nrow < lines.size() && ncol < lines[0].size() && (lines[nrow][ncol] == '.' || lines[nrow][ncol] == 'S') ) { 51 if ( nrow < height && ncol < width && lines[nrow][ncol] != '#' ) {
49 neighbours.emplace(nrow, ncol); 52 neighbours.emplace(nrow, ncol);
50 } 53 }
51 } 54 }