diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-12-15 09:14:09 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-12-15 09:14:09 +0100 |
| commit | 9ecea0012b98f42debd536dc863b4ef2501eb859 (patch) | |
| tree | 300c71eb7e7c2c5c749eb3cc0b35a955d32385f2 /2024/12 | |
| parent | e2a90aab7febe9ca73661d17a26fcb0dd10a68a7 (diff) | |
| download | aoc-9ecea0012b98f42debd536dc863b4ef2501eb859.tar.gz aoc-9ecea0012b98f42debd536dc863b4ef2501eb859.zip | |
fixed old code for non-square maps
Diffstat (limited to '2024/12')
| -rw-r--r-- | 2024/12/day12a.cpp | 6 | ||||
| -rw-r--r-- | 2024/12/day12b.cpp | 6 |
2 files changed, 6 insertions, 6 deletions
diff --git a/2024/12/day12a.cpp b/2024/12/day12a.cpp index b972fd2..89cc3d9 100644 --- a/2024/12/day12a.cpp +++ b/2024/12/day12a.cpp | |||
| @@ -46,8 +46,8 @@ public: | |||
| 46 | cells = new char[M * N]; | 46 | cells = new char[M * N]; |
| 47 | for (int i = 0; i < N; i++) { | 47 | for (int i = 0; i < N; i++) { |
| 48 | for (int j = 0; j < M; j++) { | 48 | for (int j = 0; j < M; j++) { |
| 49 | region[N*i + j] = -1; | 49 | region[M*i + j] = -1; |
| 50 | cells[N*i + j] = j < (int)lines[i].size() ? | 50 | cells[M*i + j] = j < (int)lines[i].size() ? |
| 51 | lines[i][j] : out_of_bound; | 51 | lines[i][j] : out_of_bound; |
| 52 | } | 52 | } |
| 53 | } | 53 | } |
| @@ -74,7 +74,7 @@ private: | |||
| 74 | 74 | ||
| 75 | int coord(pair<int, int> p) { | 75 | int coord(pair<int, int> p) { |
| 76 | auto [i, j] = p; | 76 | auto [i, j] = p; |
| 77 | return i >= N || i < 0 || j >= M || j < 0 ? -1 : N*i + j; | 77 | return i >= N || i < 0 || j >= M || j < 0 ? -1 : M*i + j; |
| 78 | } | 78 | } |
| 79 | }; | 79 | }; |
| 80 | 80 | ||
diff --git a/2024/12/day12b.cpp b/2024/12/day12b.cpp index 4078fa7..987df47 100644 --- a/2024/12/day12b.cpp +++ b/2024/12/day12b.cpp | |||
| @@ -57,8 +57,8 @@ public: | |||
| 57 | { | 57 | { |
| 58 | for (int64_t i = 0; i < N; i++) { | 58 | for (int64_t i = 0; i < N; i++) { |
| 59 | for (int64_t j = 0; j < M; j++) { | 59 | for (int64_t j = 0; j < M; j++) { |
| 60 | region[N*i+j] = -1; | 60 | region[M*i+j] = -1; |
| 61 | cells[N*i+j] = lines[i][j]; | 61 | cells[M*i+j] = lines[i][j]; |
| 62 | } | 62 | } |
| 63 | } | 63 | } |
| 64 | } | 64 | } |
| @@ -107,7 +107,7 @@ private: | |||
| 107 | 107 | ||
| 108 | int64_t coord(const Position p) const { | 108 | int64_t coord(const Position p) const { |
| 109 | auto [i, j] = p; | 109 | auto [i, j] = p; |
| 110 | return i >= N || i < 0 || j >= M || j < 0 ? -1 : N * i + j; | 110 | return i >= N || i < 0 || j >= M || j < 0 ? -1 : M * i + j; |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | bool is_visited(const Position p, const Direction d) const { | 113 | bool is_visited(const Position p, const Direction d) const { |
