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

- Advent of Code - 157/450 ⭐ + Advent of Code - 158/450 ⭐

2023 - 47 ⭐ @@ -132,7 +132,7 @@ My solutions to the yearly Advents of Code

- 2019 - 30 ⭐ + 2019 - 31 ⭐

@@ -179,6 +179,9 @@ My solutions to the yearly Advents of Code + + +

2015 - 50 ⭐