From ac0ae55b0c2cec33a18b9a4e1ebe3558f3467b57 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Mon, 6 Dec 2021 21:53:31 +0100 Subject: Add day 5 solutions --- 2017/05/Makefile | 7 + 2017/05/input | 1090 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2017/05/puzzles.c | 38 ++ 3 files changed, 1135 insertions(+) create mode 100644 2017/05/Makefile create mode 100644 2017/05/input create mode 100644 2017/05/puzzles.c (limited to '2017/05') diff --git a/2017/05/Makefile b/2017/05/Makefile new file mode 100644 index 0000000..b81afcc --- /dev/null +++ b/2017/05/Makefile @@ -0,0 +1,7 @@ +all: + ${CC} ${CFLAGS} -DPROGLEN=`wc -l +#include +#include + +int +main(void) +{ + int n, s; + int *jumps; + FILE *fp; + + if (!(jumps = calloc(PROGLEN, sizeof(int)))) + err(EXIT_FAILURE, "calloc"); + if (!(fp = fopen("input", "r"))) + err(EXIT_FAILURE, "fopen"); + for (int i = 0; fscanf(fp, "%d", &n) != EOF; i++) + jumps[i] = n; + fclose(fp); + + s = 0; + for (int i = 0; i >= 0 && i < PROGLEN; s++) { +#ifdef PART2 + if (jumps[i] >= 3) { + jumps[i]--; + i += jumps[i] + 1; + } else { + jumps[i]++; + i += jumps[i] - 1; + } +#else + jumps[i]++; + i += jumps[i] - 1; +#endif + } + + printf("%d\n", s); + return EXIT_SUCCESS; +} -- cgit v1.2.3