From 8c699b03d9c52c08c0543e3897229f0a32900c9b Mon Sep 17 00:00:00 2001 From: StarlitGhost <679547+StarlitGhost@users.noreply.github.com> Date: Tue, 2 Jan 2024 07:22:39 +0000 Subject: [PATCH] [2019/16] solved p1 --- 2019/16/example | 1 + 2019/16/script.py | 38 ++++++++++++++++++++++++++++++++++++++ README.md | 7 +++++-- 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 2019/16/example create mode 100644 2019/16/script.py diff --git a/2019/16/example b/2019/16/example new file mode 100644 index 0000000..a0d6069 --- /dev/null +++ b/2019/16/example @@ -0,0 +1 @@ +80871224585914546619083218645595 diff --git a/2019/16/script.py b/2019/16/script.py new file mode 100644 index 0000000..687ed15 --- /dev/null +++ b/2019/16/script.py @@ -0,0 +1,38 @@ +from GhostyUtils import aoc + + +def fft(signal: list[int]) -> list[int]: + pattern = [0, 1, 0, -1] + output = [] + for o in range(len(signal)): + out = 0 + for i, n in enumerate(signal): + mul = pattern[((i + 1) // (o + 1)) % len(pattern)] + out += n * mul + output.append(abs(out) % 10) + return output + + +def test() -> bool: + data = [ + {'in': "12345678", + 'out': "48226158"}, + ] + for d in data: + input = [int(n) for n in d['in']] + output = [int(n) for n in d['out']] + assert fft(input) == output + + +def main(): + test() + + signal = [int(n) for n in aoc.read()] + + for _ in range(100): + signal = fft(signal) + print(''.join(str(s) for s in signal[:8])) + + +if __name__ == "__main__": + main() diff --git a/README.md b/README.md index 20677e4..979b033 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ My solutions to the yearly Advents of Code