diff options
author | Marvin Borner | 2020-12-13 10:19:19 +0100 |
---|---|---|
committer | Marvin Borner | 2020-12-13 10:19:19 +0100 |
commit | a8cd821e7c7b852f2f4e9f134db4d0247717e5cc (patch) | |
tree | 2e37ebefc3d31d3a011b02c83bec6eb91a673be2 | |
parent | 99805b864c6c1e94946ea197b4917d9c42ed33bc (diff) |
13 a
-rw-r--r-- | 2020/13/Makefile | 10 | ||||
-rw-r--r-- | 2020/13/input | 2 | ||||
-rw-r--r-- | 2020/13/solve.c | 59 |
3 files changed, 71 insertions, 0 deletions
diff --git a/2020/13/Makefile b/2020/13/Makefile new file mode 100644 index 0000000..58d64e6 --- /dev/null +++ b/2020/13/Makefile @@ -0,0 +1,10 @@ +.PHONY: solve.c + +solve.o: solve.c + @gcc -Ofast $+ -o $@ -lm + +clean: + @rm -f *.o + +run: solve.o + @./solve.o diff --git a/2020/13/input b/2020/13/input new file mode 100644 index 0000000..fb48dd9 --- /dev/null +++ b/2020/13/input @@ -0,0 +1,2 @@ +1000495 +19,x,x,x,x,x,x,x,x,41,x,x,x,x,x,x,x,x,x,521,x,x,x,x,x,x,x,23,x,x,x,x,x,x,x,x,17,x,x,x,x,x,x,x,x,x,x,x,29,x,523,x,x,x,x,x,37,x,x,x,x,x,x,13 diff --git a/2020/13/solve.c b/2020/13/solve.c new file mode 100644 index 0000000..b754518 --- /dev/null +++ b/2020/13/solve.c @@ -0,0 +1,59 @@ +#include <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +int part_one(char *data) +{ + // Strange parsing + int note_earliest = 0, note_line = 0, note_service_index = 0; + int note_in_service[128] = { 0 }; + for (char *p = data; *p; p++) { + if (*p == '\n') { + note_line++; + continue; + } else if (*p == 'x') { + p++; + continue; + } + + if (!note_earliest && note_line == 0) { + sscanf(p, "%d\n", ¬e_earliest); + } else if (note_earliest && note_line == 1) { + sscanf(p, "%d,", ¬e_in_service[note_service_index]); + p += (int)(floor(log10(note_in_service[note_service_index])) + 1); // idk + note_service_index++; + } + } + + // Strange loops + for (int time = note_earliest;; time++) { + for (int *bus = note_in_service; *bus != 0; bus++) { + if (time % *bus == 0) + return (time - note_earliest) * *bus; + } + } +} + +int part_two(char *data) +{ + int res = 0; + + return res; +} + +#define SIZE 20000 +int main(int argc, char *argv[]) +{ + FILE *fp = fopen("input", "r"); + if (!fp) + exit(EXIT_FAILURE); + char buf[SIZE] = { 0 }; + fread(buf, SIZE, 1, fp); + + printf("%d\n", part_one(buf)); + printf("%d\n", part_two(buf)); + + fclose(fp); + return 0; +} |