From 87b3a0997e7ee1b9b3a07f6339261dd954a65584 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Fri, 25 Dec 2020 17:54:42 +0100 Subject: Merry christmas! --- 2020/25/solve.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 2020/25/solve.c (limited to '2020/25/solve.c') diff --git a/2020/25/solve.c b/2020/25/solve.c new file mode 100644 index 0000000..fd6542e --- /dev/null +++ b/2020/25/solve.c @@ -0,0 +1,46 @@ +#include +#include +#include + +#define MAGIC 20201227 + +long part_one(FILE *fp) +{ + long res = 1; + + int pub1, pub2; + fscanf(fp, "%d\n%d", &pub1, &pub2); + + int loop1 = 1; + long val = 1; + while (val != pub1 && loop1++) + val = (val * 7) % MAGIC; + + for (int i = 0; i < loop1 - 1; i++) + res = (res * pub2) % MAGIC; + return res; +} + +long part_two(FILE *fp) +{ + long res = 0; + // Merry christmas! + return res; +} + +int main(int argc, char *argv[]) +{ + FILE *fp = fopen("input", "r"); + if (!fp) + exit(EXIT_FAILURE); + + clock_t tic = clock(); + printf("%lu\n", part_one(fp)); + rewind(fp); + printf("%lu\n", part_two(fp)); + clock_t toc = clock(); + printf("TIME: %f seconds\n", (double)(toc - tic) / CLOCKS_PER_SEC); + + fclose(fp); + return 0; +} -- cgit v1.2.3