From 2f2b4194c6c34ece6a80e403c3ec420ea3f8bf03 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Thu, 7 Dec 2023 00:29:49 +0400 Subject: [PATCH] A little refactoring for day 3. --- day3/p1.c | 6 +++--- day3/p2.c | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/day3/p1.c b/day3/p1.c index f4dc094..3bd1572 100644 --- a/day3/p1.c +++ b/day3/p1.c @@ -3,10 +3,11 @@ #include #include #include -#include + #define ISDIGIT(c) (c >= 0x30 && c <= 0x39) + int main(int argc, char **argv) { FILE *input; char *line = NULL; @@ -57,9 +58,8 @@ int main(int argc, char **argv) { ((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] != '.'))) { + ((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) { diff --git a/day3/p2.c b/day3/p2.c index 78d24b3..bead4db 100644 --- a/day3/p2.c +++ b/day3/p2.c @@ -3,12 +3,13 @@ #include #include #include -#include + #define ISDIGIT(c) (c >= 0x30 && c <= 0x39) uint64_t parse_number(char *line, ssize_t j); + int main(int argc, char **argv) { FILE *input; char *line = NULL;