-
Notifications
You must be signed in to change notification settings - Fork 0
/
day25.py
122 lines (96 loc) · 3.34 KB
/
day25.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from util import print_ascii, print_answer
from intcode import Program, make_program
def part1(program):
user_input = None
saved_states = dict()
items = set()
route = ["west",
"take cake",
"west",
"south",
"take monolith",
"north",
"west",
"south",
"east",
"east",
"east",
"take mug",
"west",
"west",
"west",
"north",
"east",
"east",
"east",
"south",
"take coin",
"south",
"west",
"north",
"north",
"north"]
# Run until program finishes
while not program.finished:
# Run program with the user input
program.run(user_input)
print_ascii(program.output_buffer)
# Loop getting input until machine command given
run_again = False
while not run_again:
u_input = input().strip()
# Commands not for machine: save and load
# Save state with given name
if u_input[:4] == "save":
if not u_input[5:]:
print("Please specify a save name")
saved_states[u_input[5:]] = program.copy()
print("Saved", u_input[5:])
continue
# Load given state
if u_input[:4] == "load":
# If no/invalid state name given
if not u_input[5:] or u_input[5:] not in saved_states:
# List available states
print("Available load commands:")
for save in saved_states:
print("load", save)
else:
# Load specified state
program = saved_states[u_input[5:]]
print("Loaded", u_input[5:])
continue
# Enhanced commands: Drop *, run route
# Drop all items
if u_input == "drop *":
for item in items:
program.run([ord(c)
for c in ("drop " + item + "\n")])
print_ascii(program.output_buffer)
continue
# Run route found
if u_input == "run route":
for instruction in route:
program.run([ord(c)
for c in (instruction + "\n")])
print_ascii(program.output_buffer)
continue
# Commands for machine
# Auto save state on move
if u_input in ["north", "south", "east", "west"]:
saved_states["auto"] = program.copy()
# Add any taken item to list - can then be dropped in "drop *"
if u_input[:4] == "take":
items.add(u_input[5:])
# Convert ascii text to numbers
user_input = [ord(c) for c in (u_input + "\n")]
# Run intcode on next loop
run_again = True
def part2():
return 0
if __name__ == "__main__":
part1_correct = None
part2_correct = None
program = Program("25")
print_answer(1, part1(program), part1_correct)
print_answer(2, part2(), part2_correct)