aboutsummaryrefslogtreecommitdiff
path: root/2023/05/5b.c
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2023-12-25 17:56:34 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2023-12-25 17:56:34 +0100
commit94d0033ed89bb5bfb6500051296892fb7cea6c29 (patch)
tree245eac2218310c958c2df2fad5109ea4f7b2a9d9 /2023/05/5b.c
parent6a480c4eb9c96c82a8fd3663f0fbee4d32e56f19 (diff)
downloadaoc-94d0033ed89bb5bfb6500051296892fb7cea6c29.tar.gz
aoc-94d0033ed89bb5bfb6500051296892fb7cea6c29.zip
Small cleanup
Diffstat (limited to '2023/05/5b.c')
-rw-r--r--2023/05/5b.c10
1 files changed, 4 insertions, 6 deletions
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 @@
1/* For part 2 we save ranges as (first, last) instead of (first, length) */ 1/* For part 2 we save ranges as (first, last) instead of (first, length) */
2 2
3#include <inttypes.h> 3#include <inttypes.h>
4#include <stdbool.h>
5#include <stdio.h> 4#include <stdio.h>
6#include <stdlib.h> 5#include <stdlib.h>
7#include <string.h> 6#include <string.h>
8 7
9#define N 10000 8#define N 10000
10 9#define ISNUM(c) (c >= '0' && c <= '9')
11#define MIN(a, b) ((a)<(b)?(a):(b)) 10#define MIN(a, b) ((a)<(b)?(a):(b))
12#define MAX(a, b) ((a)>(b)?(a):(b)) 11#define MAX(a, b) ((a)>(b)?(a):(b))
13 12
14bool isnum(char c) { return c >= '0' && c <= '9'; }
15 13
16void append(int64_t dst[][2], int64_t src[][2], int64_t *nr, int64_t *nnr) { 14void append(int64_t dst[][2], int64_t src[][2], int64_t *nr, int64_t *nnr) {
17 for (int i = 0; i < *nnr; i++) { 15 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) {
25int64_t readl(int64_t nums[], char *buf) { 23int64_t readl(int64_t nums[], char *buf) {
26 int64_t i; 24 int64_t i;
27 for (i = 0; *buf; buf++) { 25 for (i = 0; *buf; buf++) {
28 if (!isnum(*buf)) continue; 26 if (!ISNUM(*buf)) continue;
29 nums[i++] = atoll(buf); 27 nums[i++] = atoll(buf);
30 while (isnum(*buf)) buf++; 28 while (ISNUM(*buf)) buf++;
31 } 29 }
32 return i; 30 return i;
33} 31}
@@ -43,7 +41,7 @@ int main() {
43 } 41 }
44 42
45 for (nr = 0; (buf = fgets(line, N, stdin)) != NULL; ) { 43 for (nr = 0; (buf = fgets(line, N, stdin)) != NULL; ) {
46 if (!isnum(*buf)) { 44 if (!ISNUM(*buf)) {
47 append(range, next, &nr, &nnr); 45 append(range, next, &nr, &nnr);
48 continue; 46 continue;
49 } 47 }

Generated with cgit - Back to sebastiano.tronto.net