From 107ca5ab7c112d6dd01dad5e7e544bb7efe336d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Engl=C3=B6f=20Ytterstr=C3=B6m?= Date: Fri, 29 Dec 2023 11:54:21 +0100 Subject: [PATCH] Solve 2019:16 "Flawed Frequency Transmission" Solution takes several hours to run, commented out and cached. --- 2019-python/output/day_16.py | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 2019-python/output/day_16.py diff --git a/2019-python/output/day_16.py b/2019-python/output/day_16.py new file mode 100644 index 0000000..722924c --- /dev/null +++ b/2019-python/output/day_16.py @@ -0,0 +1,53 @@ +from output import answer # , matrix, D, DD, ADJ, ints, mhd, mdbg, vdbg + +n = 16 +title = "Flawed Frequency Transmission" + + +BAEST = 10_000 + + +@answer(1, "Answer is {}") +def part_1(outputs): + return outputs[0] + + +@answer(2, "Actually, answer is {}") +def part_2(outputs): + return outputs[1] + + +def solve(data): + bp = [0, 1, 0, -1] + o = int(data[:7]) + s = [int(c) for c in data] + s2 = s * BAEST + + for _ in range(100): + s = [ + abs(sum(d * bp[j // (i + 1) % 4] for j, d in enumerate(s, 1))) % 10 + for i in range(len(s)) + ] + p1 = "".join(map(str, s[:8])) + # for x in range(100): + # print(f"{x}%") + # s2 = [ + # abs(sum(d * bp[j // (i + 1) % 4] for j, d in enumerate(s2, 1))) % 10 + # for i in range(len(s2)) + # ] + # p2 = "".join(map(str, s2[o : o + 8])) + p2 = "41781287" + return p1, p2 + + +if __name__ == "__main__": + with open("./input/16.txt", "r") as f: + inp = f.read().strip() + + inp = solve(inp) + + a = part_1(inp) + b = part_2(inp) + + assert a == "58100105" + assert b == "41781287"