aoc

My solutions for the Advent of Code
git clone https://git.tronto.net/aoc
Download | Log | Files | Refs | README

commit 8d33eef329a433ee50a7c045cb3e9091b5febf90
parent 758fdc7115cbf08d38ad8e700de9f8a6734fc406
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Sun, 15 Dec 2024 09:14:09 +0100

fixed old code for non-square maps

Diffstat:
M2024/04/day04a.cpp | 4++--
M2024/04/day04b.cpp | 4++--
M2024/06/day06a.cpp | 4++--
M2024/06/day06b.cpp | 6+++---
M2024/10/day10a.cpp | 4++--
M2024/10/day10b.cpp | 4++--
M2024/12/day12a.cpp | 6+++---
M2024/12/day12b.cpp | 6+++---
8 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/2024/04/day04a.cpp b/2024/04/day04a.cpp @@ -49,7 +49,7 @@ public: cells = new char[M * N]; for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) - cells[N*i + j] = j < (int)lines[i].size() ? + cells[M*i + j] = j < (int)lines[i].size() ? lines[i][j] : out_of_bound; } @@ -73,7 +73,7 @@ private: auto [i, j] = p; if (i >= N || i < 0 || j >= M || j < 0) return out_of_bound; - return cells[N*i + j]; + return cells[M*i + j]; } }; diff --git a/2024/04/day04b.cpp b/2024/04/day04b.cpp @@ -49,7 +49,7 @@ public: cells = new char[M * N]; for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) - cells[N*i + j] = j < (int)lines[i].size() ? + cells[M*i + j] = j < (int)lines[i].size() ? lines[i][j] : out_of_bound; } @@ -73,7 +73,7 @@ private: auto [i, j] = p; if (i >= N || i < 0 || j >= M || j < 0) return out_of_bound; - return cells[N*i + j]; + return cells[M*i + j]; } }; diff --git a/2024/06/day06a.cpp b/2024/06/day06a.cpp @@ -55,7 +55,7 @@ public: cells = new char[M * N]; for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) - cells[N*i + j] = j < (int)lines[i].size() ? + cells[M*i + j] = j < (int)lines[i].size() ? lines[i][j] : out_of_bound; } @@ -86,7 +86,7 @@ private: int coord(pair<int, int> p) { auto [i, j] = p; - return i >= N || i < 0 || j >= M || j < 0 ? -1 : N*i + j; + return i >= N || i < 0 || j >= M || j < 0 ? -1 : M*i + j; } }; diff --git a/2024/06/day06b.cpp b/2024/06/day06b.cpp @@ -62,9 +62,9 @@ public: visited = new int[M * N]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { - cells[N*i + j] = j < (int)lines[i].size() ? + cells[M*i + j] = j < (int)lines[i].size() ? lines[i][j] : out_of_bound; - visited[N*i + j] = 0; + visited[M*i + j] = 0; } } } @@ -111,7 +111,7 @@ private: int coord(pair<int, int> p) { auto [i, j] = p; - return i >= N || i < 0 || j >= M || j < 0 ? -1 : N*i + j; + return i >= N || i < 0 || j >= M || j < 0 ? -1 : M*i + j; } void set_cell(pair<int, int> p, char c) { diff --git a/2024/10/day10a.cpp b/2024/10/day10a.cpp @@ -42,7 +42,7 @@ public: cells = new int[M * N]; for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) - cells[N*i + j] = lines[i][j] - '0'; + cells[M*i + j] = lines[i][j] - '0'; } ~Board() { @@ -59,7 +59,7 @@ private: int coord(pair<int, int> p) { auto [i, j] = p; - return i >= N || i < 0 || j >= M || j < 0 ? -1 : N*i + j; + return i >= N || i < 0 || j >= M || j < 0 ? -1 : M*i + j; } }; diff --git a/2024/10/day10b.cpp b/2024/10/day10b.cpp @@ -42,7 +42,7 @@ public: cells = new int[M * N]; for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) - cells[N*i + j] = lines[i][j] - '0'; + cells[M*i + j] = lines[i][j] - '0'; } ~Board() { @@ -59,7 +59,7 @@ private: int coord(pair<int, int> p) { auto [i, j] = p; - return i >= N || i < 0 || j >= M || j < 0 ? -1 : N*i + j; + return i >= N || i < 0 || j >= M || j < 0 ? -1 : M*i + j; } }; diff --git a/2024/12/day12a.cpp b/2024/12/day12a.cpp @@ -46,8 +46,8 @@ public: cells = new char[M * N]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { - region[N*i + j] = -1; - cells[N*i + j] = j < (int)lines[i].size() ? + region[M*i + j] = -1; + cells[M*i + j] = j < (int)lines[i].size() ? lines[i][j] : out_of_bound; } } @@ -74,7 +74,7 @@ private: int coord(pair<int, int> p) { auto [i, j] = p; - return i >= N || i < 0 || j >= M || j < 0 ? -1 : N*i + j; + return i >= N || i < 0 || j >= M || j < 0 ? -1 : M*i + j; } }; diff --git a/2024/12/day12b.cpp b/2024/12/day12b.cpp @@ -57,8 +57,8 @@ public: { for (int64_t i = 0; i < N; i++) { for (int64_t j = 0; j < M; j++) { - region[N*i+j] = -1; - cells[N*i+j] = lines[i][j]; + region[M*i+j] = -1; + cells[M*i+j] = lines[i][j]; } } } @@ -107,7 +107,7 @@ private: int64_t coord(const Position p) const { auto [i, j] = p; - return i >= N || i < 0 || j >= M || j < 0 ? -1 : N * i + j; + return i >= N || i < 0 || j >= M || j < 0 ? -1 : M * i + j; } bool is_visited(const Position p, const Direction d) const {