summaryrefslogtreecommitdiff
path: root/4b.c
diff options
context:
space:
mode:
authorAdam Spragg <adam@spra.gg>2023-01-15 10:36:48 +0000
committerAdam Spragg <adam@spra.gg>2023-01-15 10:36:48 +0000
commit8528013fb10ae7aedb6a40f5ece5ee08eb42e9df (patch)
treec34f91708adef795a29a092395c49717940b246b /4b.c
parent3dd30be057332cd764ee79a26673a775336322eb (diff)
Puzzle 4: Consolidate 4a/4b programs into `4` with `-p` option
Like the later puzzles
Diffstat (limited to '4b.c')
-rw-r--r--4b.c51
1 files changed, 0 insertions, 51 deletions
diff --git a/4b.c b/4b.c
deleted file mode 100644
index 6f43c21..0000000
--- a/4b.c
+++ /dev/null
@@ -1,51 +0,0 @@
-
-#include <stdio.h>
-#include <stdlib.h>
-
-
-char *
-getsect(int * dest, char * pch, char expect)
-{
- char * end;
-
- if (!pch)
- return NULL;
- *dest = strtol(pch, &end, 10);
- if (*dest == 0 && end == pch)
- return NULL;
- if (*end != expect)
- return NULL;
- if (expect)
- ++end;
- return end;
-}
-
-
-int
-main()
-{
- char buf[BUFSIZ];
- int overlaps = 0;
-
- while (fgets(buf, sizeof(buf), stdin)) {
- int n[4];
- char * pbuf;
-
- pbuf = getsect(&n[0], buf, '-');
- pbuf = getsect(&n[1], pbuf, ',');
- pbuf = getsect(&n[2], pbuf, '-');
- pbuf = getsect(&n[3], pbuf, '\n');
- if (!pbuf) {
- fprintf(stderr, "Unexpected line: %s\n", buf);
- return -1;
- }
- if (!(n[3] < n[0] || n[2] > n[1])) {
- ++overlaps;
- }
- }
-
- printf("Overlaps: %d\n", overlaps);
-
- return 0;
-}
-