-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday21.py
executable file
·58 lines (45 loc) · 952 Bytes
/
day21.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
# [Day 21: Springdroid Adventure](https://adventofcode.com/2019/day/21)
import sys
from pathlib import Path
filename = ("test.txt" if sys.argv[1] == "-t" else sys.argv[1]) if len(sys.argv) > 1 else "input.txt"
data = Path(filename).read_text()
lines = data.splitlines()
sys.path.append(Path(__file__).parent.parent.as_posix())
from intcode.Intcode import Computer # noqa
filename = sys.argv[1] if len(sys.argv) > 1 else "input.txt"
software = Path(filename).read_text()
droid = Computer()
droid.load(software)
def run_script(script):
droid.flush_io()
droid.input.extend(map(ord, script))
droid.run()
res = droid.output[-1]
if res == 10:
print("error")
else:
print(res)
# J = not A or not (C and D)
run_script(
"""\
NOT A J
NOT C T
AND D T
OR T J
WALK
"""
)
# J = not A or not (C and D)
run_script(
"""\
NOT B J
NOT C T
OR T J
AND D J
AND H J
NOT A T
OR T J
RUN
"""
)