Day 21
This commit is contained in:
parent
8992b18382
commit
1c0ad51b60
6
2019/day21-p1.springscript
Normal file
6
2019/day21-p1.springscript
Normal file
|
@ -0,0 +1,6 @@
|
|||
OR D J
|
||||
NOT C T
|
||||
AND T J
|
||||
NOT A T
|
||||
OR T J
|
||||
WALK
|
20
2019/day21.py
Normal file
20
2019/day21.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
import sys
|
||||
|
||||
from intcode import AIC
|
||||
|
||||
|
||||
def main():
|
||||
codes = AIC.parse_file("day21.txt")
|
||||
ss = SSIC(codes, script=sys.stdin.read())
|
||||
ss.run()
|
||||
|
||||
|
||||
class SSIC(AIC):
|
||||
|
||||
def __init__(self, *args, script="", **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.input_text = script
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -162,3 +162,25 @@ class Intcode(object):
|
|||
|
||||
def output_data(self, data):
|
||||
print(">", data)
|
||||
|
||||
|
||||
class AIC(Intcode):
|
||||
"""ASCII-enabled Intcode interpreter."""
|
||||
LN = ord("\n")
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.input_text = ""
|
||||
|
||||
def input_data(self):
|
||||
data, self.input_text = self.input_text[0], self.input_text[1:]
|
||||
return ord(data)
|
||||
|
||||
def output_data(self, data):
|
||||
if data > 256:
|
||||
self.handle_int_output(data)
|
||||
else:
|
||||
print(chr(data), end="")
|
||||
|
||||
def handle_int_output(self, i):
|
||||
print(f"Int output: {i}.")
|
||||
|
|
Loading…
Reference in a new issue