From 2d3e387f4f68802fd0aaec0f47377291ca4cfcd2 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sun, 3 Dec 2023 19:01:32 +0400 Subject: [PATCH] Bring ISDIGIT macro in part 1 of the day 3 as well. --- day3/p1.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/day3/p1.c b/day3/p1.c index 8823abc..f0aaa6a 100644 --- a/day3/p1.c +++ b/day3/p1.c @@ -4,7 +4,8 @@ #include #include #include -#include + +#define ISDIGIT(c) (c >= 0x30 && c <= 0x39) int main(int argc, char **argv) { FILE *input; @@ -44,22 +45,22 @@ int main(int argc, char **argv) { for (ssize_t i = engine_lines-1; i >= 0; --i) { for (ssize_t j = engine_line_size-1; j >= 0; --j) { - if (isdigit(engine[i][j])) { + if (ISDIGIT(engine[i][j])) { n += (engine[i][j]&0xf) * multiplier; multiplier *= 10; - if (adjacent == false && ((j+1 <= engine_line_size-1 && !isdigit(engine[i][j+1]) && engine[i][j+1] != '.') || - (j-1 >=0 && !isdigit(engine[i][j-1]) && engine[i][j-1] != '.') || - (i+1 <= engine_lines-1 && !isdigit(engine[i+1][j]) && engine[i+1][j] != '.') || - (i-1 >= 0 && !isdigit(engine[i-1][j]) && engine[i-1][j] != '.') || - ((i+1 <= engine_lines-1 && j+1 <= engine_line_size-1) && !isdigit(engine[i+1][j+1]) && engine[i+1][j+1] != '.') || - ((i+1 <= engine_lines-1 && j-1 >= 0) && !isdigit(engine[i+1][j-1]) && engine[i+1][j-1] != '.') || - ((i-1 >= 0 && j+1 <= engine_line_size-1) && !isdigit(engine[i-1][j+1]) && engine[i-1][j+1] != '.') || - ((i-1 >= 0 && j-1 >= 0) && !isdigit(engine[i-1][j-1]) && engine[i-1][j-1] != '.'))) { + if (adjacent == false && ((j+1 <= engine_line_size-1 && !ISDIGIT(engine[i][j+1]) && engine[i][j+1] != '.') || + (j-1 >=0 && !ISDIGIT(engine[i][j-1]) && engine[i][j-1] != '.') || + (i+1 <= engine_lines-1 && !ISDIGIT(engine[i+1][j]) && engine[i+1][j] != '.') || + (i-1 >= 0 && !ISDIGIT(engine[i-1][j]) && engine[i-1][j] != '.') || + ((i+1 <= engine_lines-1 && j+1 <= engine_line_size-1) && !ISDIGIT(engine[i+1][j+1]) && engine[i+1][j+1] != '.') || + ((i+1 <= engine_lines-1 && j-1 >= 0) && !ISDIGIT(engine[i+1][j-1]) && engine[i+1][j-1] != '.') || + ((i-1 >= 0 && j+1 <= engine_line_size-1) && !ISDIGIT(engine[i-1][j+1]) && engine[i-1][j+1] != '.') || + ((i-1 >= 0 && j-1 >= 0) && !ISDIGIT(engine[i-1][j-1]) && engine[i-1][j-1] != '.'))) { adjacent = true; } } - if ((!isdigit(engine[i][j]) || j == 0) && n != 0) { + if ((!ISDIGIT(engine[i][j]) || j == 0) && n != 0) { if (adjacent) part_number += n; n = 0;