Skip to content

Commit

Permalink
[2019/16] solved p1
Browse files Browse the repository at this point in the history
  • Loading branch information
StarlitGhost committed Jan 2, 2024
1 parent 30b5168 commit 8c699b0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
1 change: 1 addition & 0 deletions 2019/16/example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
80871224585914546619083218645595
38 changes: 38 additions & 0 deletions 2019/16/script.py
Original file line number Diff line number Diff line change
@@ -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()
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ My solutions to the yearly Advents of Code

<!-- AOC TILES BEGIN -->
<h1 align="center">
Advent of Code - 157/450 ⭐
Advent of Code - 158/450 ⭐
</h1>
<h1 align="center">
2023 - 47 ⭐
Expand Down Expand Up @@ -132,7 +132,7 @@ My solutions to the yearly Advents of Code
<img src=".aoc_tiles/tiles/2022/15.png" width="161px">
</a>
<h1 align="center">
2019 - 30
2019 - 31
</h1>
<a href="2019/1/script.py">
<img src=".aoc_tiles/tiles/2019/01.png" width="161px">
Expand Down Expand Up @@ -179,6 +179,9 @@ My solutions to the yearly Advents of Code
<a href="2019/15/script.py">
<img src=".aoc_tiles/tiles/2019/15.png" width="161px">
</a>
<a href="2019/16/script.py">
<img src=".aoc_tiles/tiles/2019/16.png" width="161px">
</a>
<h1 align="center">
2015 - 50 ⭐
</h1>
Expand Down

0 comments on commit 8c699b0

Please sign in to comment.