From 94d0033ed89bb5bfb6500051296892fb7cea6c29 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Mon, 25 Dec 2023 17:56:34 +0100 Subject: Small cleanup --- 2023/05/5b.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to '2023/05/5b.c') diff --git a/2023/05/5b.c b/2023/05/5b.c index aeac8c0..c59f61b 100644 --- a/2023/05/5b.c +++ b/2023/05/5b.c @@ -1,17 +1,15 @@ /* For part 2 we save ranges as (first, last) instead of (first, length) */ #include -#include #include #include #include #define N 10000 - +#define ISNUM(c) (c >= '0' && c <= '9') #define MIN(a, b) ((a)<(b)?(a):(b)) #define MAX(a, b) ((a)>(b)?(a):(b)) -bool isnum(char c) { return c >= '0' && c <= '9'; } void append(int64_t dst[][2], int64_t src[][2], int64_t *nr, int64_t *nnr) { for (int i = 0; i < *nnr; i++) { @@ -25,9 +23,9 @@ void append(int64_t dst[][2], int64_t src[][2], int64_t *nr, int64_t *nnr) { int64_t readl(int64_t nums[], char *buf) { int64_t i; for (i = 0; *buf; buf++) { - if (!isnum(*buf)) continue; + if (!ISNUM(*buf)) continue; nums[i++] = atoll(buf); - while (isnum(*buf)) buf++; + while (ISNUM(*buf)) buf++; } return i; } @@ -43,7 +41,7 @@ int main() { } for (nr = 0; (buf = fgets(line, N, stdin)) != NULL; ) { - if (!isnum(*buf)) { + if (!ISNUM(*buf)) { append(range, next, &nr, &nnr); continue; } -- cgit v1.3