From 282d55c3cd8b537c4b91028b7043840e2c6820be Mon Sep 17 00:00:00 2001 From: Bruno Raoult Date: Tue, 11 Oct 2022 18:37:25 +0200 Subject: [PATCH] 2020 day 25 (C): just copied my (lazy/brute-force) bash solution --- 2020/day25/ex1-c.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 2020/day25/ex1-c.c diff --git a/2020/day25/ex1-c.c b/2020/day25/ex1-c.c new file mode 100644 index 0000000..92eb481 --- /dev/null +++ b/2020/day25/ex1-c.c @@ -0,0 +1,31 @@ +/* ex1-c: Advent2020, day 25/part 1 + */ + +#include +#include +#include + +int main(ac, av) + int ac; + char **av; +{ + ulong pub[] = {1, 1}, enc[] = {1, 1}, key[2], res; + + scanf("%lu", key); + scanf("%lu", key+1); + while (1) { + pub[0] = pub[0] * 7 % 20201227; + pub[1] = pub[1] * 7 % 20201227; + enc[0] = enc[0] * key[0] %20201227; + enc[1] = enc[1] * key[1] %20201227; + if (pub[0] == key[0]) { + res=enc[1]; + break; + } else if (pub[1] == key[1]) { + res=enc[0]; + break; + } + } + printf("%s : res=%lu\n", *av, res); + exit (0); +}