-
Notifications
You must be signed in to change notification settings - Fork 0
/
p19.py
36 lines (30 loc) · 856 Bytes
/
p19.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
from itertools import count
from aocd import data
from intcode import Computer
class Drone(Computer):
def execute(self, input_):
while (intcode := self._get_op_code()) != 99:
args = self._get_args(intcode)
op = self._get_op(intcode.op)
if intcode.op == 3:
xy = next(input_)
op(*args, xy, modes=intcode.modes)
else:
op(*args, modes=intcode.modes)
drone = Drone(data)
beam = 0
for y in count():
if y == 50:
print('Part 1:', beam)
break
x_count = count()
found_beam = False
for x in x_count:
drone.execute(iter([x, y]))
output = drone.output[-1]
drone.reset()
if output == 1:
beam += 1
found_beam = True
elif found_beam or x > 49:
break