aboutsummaryrefslogtreecommitdiff
path: root/2024/10
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-12-15 09:14:09 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2024-12-15 09:14:09 +0100
commit9ecea0012b98f42debd536dc863b4ef2501eb859 (patch)
tree300c71eb7e7c2c5c749eb3cc0b35a955d32385f2 /2024/10
parente2a90aab7febe9ca73661d17a26fcb0dd10a68a7 (diff)
downloadaoc-9ecea0012b98f42debd536dc863b4ef2501eb859.tar.gz
aoc-9ecea0012b98f42debd536dc863b4ef2501eb859.zip
fixed old code for non-square maps
Diffstat (limited to '2024/10')
-rw-r--r--2024/10/day10a.cpp4
-rw-r--r--2024/10/day10b.cpp4
2 files changed, 4 insertions, 4 deletions
diff --git a/2024/10/day10a.cpp b/2024/10/day10a.cpp
index fda4ab8..2c01ea2 100644
--- a/2024/10/day10a.cpp
+++ b/2024/10/day10a.cpp
@@ -42,7 +42,7 @@ public:
42 cells = new int[M * N]; 42 cells = new int[M * N];
43 for (int i = 0; i < N; i++) 43 for (int i = 0; i < N; i++)
44 for (int j = 0; j < M; j++) 44 for (int j = 0; j < M; j++)
45 cells[N*i + j] = lines[i][j] - '0'; 45 cells[M*i + j] = lines[i][j] - '0';
46 } 46 }
47 47
48 ~Board() { 48 ~Board() {
@@ -59,7 +59,7 @@ private:
59 59
60 int coord(pair<int, int> p) { 60 int coord(pair<int, int> p) {
61 auto [i, j] = p; 61 auto [i, j] = p;
62 return i >= N || i < 0 || j >= M || j < 0 ? -1 : N*i + j; 62 return i >= N || i < 0 || j >= M || j < 0 ? -1 : M*i + j;
63 } 63 }
64}; 64};
65 65
diff --git a/2024/10/day10b.cpp b/2024/10/day10b.cpp
index de972c0..96eb195 100644
--- a/2024/10/day10b.cpp
+++ b/2024/10/day10b.cpp
@@ -42,7 +42,7 @@ public:
42 cells = new int[M * N]; 42 cells = new int[M * N];
43 for (int i = 0; i < N; i++) 43 for (int i = 0; i < N; i++)
44 for (int j = 0; j < M; j++) 44 for (int j = 0; j < M; j++)
45 cells[N*i + j] = lines[i][j] - '0'; 45 cells[M*i + j] = lines[i][j] - '0';
46 } 46 }
47 47
48 ~Board() { 48 ~Board() {
@@ -59,7 +59,7 @@ private:
59 59
60 int coord(pair<int, int> p) { 60 int coord(pair<int, int> p) {
61 auto [i, j] = p; 61 auto [i, j] = p;
62 return i >= N || i < 0 || j >= M || j < 0 ? -1 : N*i + j; 62 return i >= N || i < 0 || j >= M || j < 0 ? -1 : M*i + j;
63 } 63 }
64}; 64};
65 65

Generated with cgit - Back to sebastiano.tronto.net