advent2023

Advent of Code 2023 solutions
git clone git://bsandro.tech/advent2023
Log | Files | Refs | LICENSE

commit 1094963efd3db16c43de4349b1ef3c1514e60f64
parent 431701cd9d7f15d78230f18a6fef25ee7925f66a
Author: bsandro <email@bsandro.tech>
Date:   Sun,  3 Dec 2023 14:26:29 +0200

day 03 p1 passing 2d array as a pointer

Diffstat:
Mday03/puzzle.c | 12+++++-------
1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/day03/puzzle.c b/day03/puzzle.c @@ -11,22 +11,20 @@ #define STR_LEN 2048 // 140x140 for real one -//#define FIELD_SIZE 10 -#define FIELD_SIZE 140 - -// 1200837 was wrong +#define FIELD_SIZE 10 +//#define FIELD_SIZE 140 bool is_digit(char b) { return b>='0' && b<='9'; } -bool check_part(int x, int y, const char field[FIELD_SIZE][FIELD_SIZE]) { +bool check_part(int x, int y, const char (*field)[FIELD_SIZE][FIELD_SIZE]) { for (int dy=-1; dy<=1; ++dy) { for (int dx=-1; dx<=1; ++dx) { int dy1=y+dy; int dx1=x+dx; if (dy1>=0 && dy1<FIELD_SIZE && dx1>=0 && dx1<FIELD_SIZE) { - if (!is_digit(field[dy1][dx1]) && field[dy1][dx1]!='.') { + if (!is_digit((*field)[dy1][dx1]) && (*field)[dy1][dx1]!='.') { return true; } } @@ -68,7 +66,7 @@ void puzzle(const char *filename, long long *result1, long long *result2) { while (is_digit(field[y][x++])) { int cx = x-1; if (cx>=FIELD_SIZE) break; // too lazy to make it sane - if (!is_part) is_part = check_part(cx, y, field); + if (!is_part) is_part = check_part(cx, y, &field); digit = digit*10 + field[y][cx] - '0'; } if (digit>0 && is_part) {