2019 day 21

This commit is contained in:
2024-09-23 19:27:26 -04:00
parent 25bd810886
commit 2eba36a29a
2 changed files with 59 additions and 1 deletions

57
2019/d21.py Normal file
View File

@@ -0,0 +1,57 @@
from lib import get_data, str_to_ints
from d9 import Amp
data = get_data(__file__)
xs = str_to_ints(data)
script = """NOT A J
AND A J
NOT C T
AND D T
OR T J
NOT A T
OR T J
"""
a = Amp(xs)
while not a.done:
a.go()
if a.input_required:
for c in script:
a.feed(ord(c))
for c in "WALK\n":
a.feed(ord(c))
while a.outputs:
c = a.pop()
try:
chr(c)
# print(chr(c), end="")
except ValueError:
print(c)
script = """NOT C J
AND H J
NOT A T
OR T J
NOT B T
OR T J
AND D J
"""
a = Amp(xs)
while not a.done:
a.go()
if a.input_required:
for c in script:
a.feed(ord(c))
for c in "RUN\n":
a.feed(ord(c))
while a.outputs:
c = a.pop()
try:
chr(c)
# print(chr(c), end="")
except ValueError:
print(c)