aboutsummaryrefslogtreecommitdiff
path: root/2020/2/solve.c
diff options
context:
space:
mode:
authorMarvin Borner2020-12-08 20:56:10 +0100
committerMarvin Borner2020-12-08 20:56:29 +0100
commita48df2144386d4779aaa73fcaaa46bcc66c79c4d (patch)
treecf5fbac2c35ee6939b750e8a9bc36d17c065b7bc /2020/2/solve.c
parentc3071578cfe3f97cfda05372ff2da64474a9d0c1 (diff)
Fixed naming for 10+ challenges
Diffstat (limited to '2020/2/solve.c')
-rw-r--r--2020/2/solve.c60
1 files changed, 0 insertions, 60 deletions
diff --git a/2020/2/solve.c b/2020/2/solve.c
deleted file mode 100644
index 6294771..0000000
--- a/2020/2/solve.c
+++ /dev/null
@@ -1,60 +0,0 @@
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-int part_one(FILE *fp)
-{
- int res = 0;
-
- char *line = NULL;
- size_t len = 0;
- while (getline(&line, &len, fp) != -1) {
- int low, high, cnt = 0;
- char ch;
- char str[42];
- sscanf(line, "%d-%d %c: %s\n", &low, &high, &ch, &str[0]);
-
- for (char *p = str; *p; p++)
- if (*p == ch)
- cnt++;
-
- if (cnt >= low && cnt <= high)
- res++;
- }
-
- return res;
-}
-
-int part_two(FILE *fp)
-{
- int res = 0;
-
- char *line = NULL;
- size_t len = 0;
- while (getline(&line, &len, fp) != -1) {
- int low, high, cnt = 0;
- char ch, first, second;
- char str[256];
- sscanf(line, "%d-%d %c: %s\n", &low, &high, &ch, &str[0]);
- first = str[low - 1];
- second = str[high - 1];
- if (first == ch && second != ch || first != ch && second == ch)
- res++;
- }
-
- return res;
-}
-
-int main(int argc, char *argv[])
-{
- FILE *fp = fopen("input", "r");
- if (!fp)
- exit(EXIT_FAILURE);
-
- printf("%d\n", part_one(fp));
- rewind(fp);
- printf("%d\n", part_two(fp));
-
- fclose(fp);
- return 0;
-}