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/puzzles.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 2017/05/puzzles.c (limited to '2017/05/puzzles.c') diff --git a/2017/05/puzzles.c b/2017/05/puzzles.c new file mode 100644 index 0000000..1f78e14 --- /dev/null +++ b/2017/05/puzzles.c @@ -0,0 +1,38 @@ +#include +#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