-
Notifications
You must be signed in to change notification settings - Fork 0
/
25.py
88 lines (79 loc) · 2.55 KB
/
25.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
import itertools
from intcode import intcode_v3, ascii_input, ascii_output
with open('../25.txt') as f:
instructions = [int(x) for x in f.read().split(',')]
droid = intcode_v3(instructions)
# directions and safe items determined manually.
commands = ['south\n',
'take astronaut ice cream\n',
'north\n',
'east\n',
'take mouse\n',
'north\n',
'take spool of cat6\n',
'north\n',
'take hypercube\n',
'east\n',
'take sand\n',
'south\n',
'take antenna\n',
'north\n',
'west\n',
'south\n',
'south\n',
'south\n',
'take mutex\n',
'west\n',
'take boulder\n',
'south\n',
'south\n',
'south\n',
'west\n',
'south\n']
items = ['astronaut ice cream',
'mouse',
'spool of cat6',
'hypercube',
'sand',
'antenna',
'mutex',
'boulder']
output = ''.join(ascii_output(droid))
#print(output, end='')
for command in commands:
#print(command)
initial = ascii_input(droid, command)
output = ''.join(ascii_output(droid, initial))
#print(output, end='')
for item in items:
#print(f'drop {item}')
initial = ascii_input(droid, f'drop {item}\n')
output = ''.join(ascii_output(droid, initial))
#print(output, end='')
print('collected all items, at security door')
try:
oldcombo = ()
for i in range(len(items)):
for combo in itertools.combinations(items, i):
for item in oldcombo:
if item not in combo:
#print(f'drop {item}')
initial = ascii_input(droid, f'drop {item}\n')
output = ''.join(ascii_output(droid, initial))
#print(output, end='')
print('trying', ', '.join(combo))
for item in combo:
if item not in oldcombo:
#print(f'take {item}')
initial = ascii_input(droid, f'take {item}\n')
output = ''.join(ascii_output(droid, initial))
#print(output, end='')
oldcombo = combo
#print('south')
initial = ascii_input(droid, 'south\n')
output = ''.join(ascii_output(droid, initial))
#print(output, end='')
if 'heavier' not in output and 'lighter' not in output:
print(output, end='')
except StopIteration:
pass