-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpuzzle25.py
More file actions
66 lines (58 loc) · 1.69 KB
/
puzzle25.py
File metadata and controls
66 lines (58 loc) · 1.69 KB
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
from intcode import IntCodeComputer
import itertools
def prints2ascii(prints, prune=True):
ascii_prints = "".join(map(chr, prints)).split('\n')
if prune:
ascii_prints = [row for row in ascii_prints if len(row) > 0]
return ascii_prints
program = list(map(int, open('data/input25').read().strip().split(',')))
computer = IntCodeComputer(program, resume=False)
cmds = """\
east
take manifold
south
take whirled peas
north
west
south
take space heater
south
take dark matter
north
east
north
west
south
take antenna
north
east
south
east
take bowl of rice
north
take klein bottle
north
take spool of cat6
west
"""
items = ['manifold', 'whirled peas', 'space heater', 'dark matter',
'antenna', 'bowl of rice', 'klein bottle', 'spool of cat6']
tooheavy = 'A loud, robotic voice says "Alert! Droids on this ship are heavier than the detected value!" and you are ejected back to the checkpoint.'
toolight = 'A loud, robotic voice says "Alert! Droids on this ship are lighter than the detected value!" and you are ejected back to the checkpoint.'
# number of items to remove
for r in range(1, len(items)):
for comb in itertools.combinations(items, r):
new_cmds = cmds[:]
for item in comb:
new_cmds += f'drop {item}\n'
new_cmds += 'north\n'
ascii_cmds = [ord(char) for char in new_cmds]
_, prints, status = computer.run(input_values=ascii_cmds)
ascii_prints = prints2ascii(prints)
if tooheavy in ascii_prints:
continue
elif toolight in ascii_prints:
continue
else:
print(f'The following dropped items do not produce a "too light" or "too heavy" message: {comb}')
break