-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday13.py
38 lines (33 loc) · 865 Bytes
/
day13.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
from intcode import *
from helpers import sign
def part1(instr):
comp = Computer(instr)
comp.run()
blocks = 0
while comp.out_queue:
_, _, tile = comp.get_3_from_output()
blocks += tile == 2
return blocks
def part2(instr):
comp = Computer(instr)
comp.set_ram(0, 2)
score = 0
ball_pos = 0
paddle_pos = 0
while comp.state != State.Halted:
comp.run()
while comp.out_queue:
x, y, t = comp.get_3_from_output()
if (x, y) == (-1, 0):
score = t
else:
if t == 3:
paddle_pos = x
elif t == 4:
ball_pos = x
joystick = sign(ball_pos - paddle_pos)
comp.receive(joystick)
return score
instr = read_intcode_input(13)
print(part1(instr))
print(part2(instr))