aboutsummaryrefslogtreecommitdiff
path: root/2023/05/5a.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/5a.c
parent6a480c4eb9c96c82a8fd3663f0fbee4d32e56f19 (diff)
downloadaoc-94d0033ed89bb5bfb6500051296892fb7cea6c29.tar.gz
aoc-94d0033ed89bb5bfb6500051296892fb7cea6c29.zip
Small cleanup
Diffstat (limited to '2023/05/5a.c')
-rw-r--r--2023/05/5a.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/2023/05/5a.c b/2023/05/5a.c
index 15d2805..14b8c7c 100644
--- a/2023/05/5a.c
+++ b/2023/05/5a.c
@@ -1,26 +1,25 @@
1#include <inttypes.h> 1#include <inttypes.h>
2#include <stdbool.h>
3#include <stdio.h> 2#include <stdio.h>
4#include <stdlib.h> 3#include <stdlib.h>
5#include <string.h> 4#include <string.h>
6 5
7#define N 100 6#define N 100
8 7#define ISNUM(c) (c >= '0' && c <= '9')
9bool isnum(char c) { return c >= '0' && c <= '9'; } 8#define MIN(x,y) ((x)<(y)?(x):(y))
10 9
11int main() { 10int main() {
12 char *buf, line[N]; 11 char *buf, line[N];
13 int64_t i, m, ns, seed[N], next[N], r[3]; 12 int64_t i, m, ns, seed[N], next[N], r[3];
14 13
15 for (ns = 0, buf = fgets(line, N, stdin); *buf; buf++) { 14 for (ns = 0, buf = fgets(line, N, stdin); *buf; buf++) {
16 if (!isnum(*buf)) continue; 15 if (!ISNUM(*buf)) continue;
17 next[ns++] = atoll(buf); 16 next[ns++] = atoll(buf);
18 while (isnum(*buf)) buf++; 17 while (ISNUM(*buf)) buf++;
19 } 18 }
20 19
21 20
22 while ((buf = fgets(line, N, stdin)) != NULL) { 21 while ((buf = fgets(line, N, stdin)) != NULL) {
23 if (!isnum(*buf)) { 22 if (!ISNUM(*buf)) {
24 memcpy(seed, next, ns * sizeof(int64_t)); 23 memcpy(seed, next, ns * sizeof(int64_t));
25 fgets(line, N, stdin); /* Discard description */ 24 fgets(line, N, stdin); /* Discard description */
26 continue; 25 continue;
@@ -28,7 +27,7 @@ int main() {
28 27
29 for (i = 0; *buf; buf++) { 28 for (i = 0; *buf; buf++) {
30 r[i++] = atoll(buf); 29 r[i++] = atoll(buf);
31 while (isnum(*buf)) buf++; 30 while (ISNUM(*buf)) buf++;
32 } 31 }
33 32
34 for (i = 0; i < ns; i++) 33 for (i = 0; i < ns; i++)
@@ -36,9 +35,8 @@ int main() {
36 next[i] = seed[i] + (r[0] - r[1]); 35 next[i] = seed[i] + (r[0] - r[1]);
37 } 36 }
38 37
39 m = next[0]; 38 for (i = 1, m = next[0]; i < ns; i++)
40 for (i = 1; i < ns; i++) 39 m = MIN(m, next[i]);
41 m = m > next[i] ? next[i] : m;
42 40
43 printf("%" PRId64 "\n", m); 41 printf("%" PRId64 "\n", m);
44 return 0; 42 return 0;

Generated with cgit - Back to sebastiano.tronto.net