-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday13.py
45 lines (36 loc) · 1 KB
/
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
39
40
41
42
43
44
45
from etc.intcode import from_file
comp = from_file("input/day13.txt")
blocks = 0
### Part 1:
while True:
try:
x, y, tile = comp.get_next_output(), comp.get_next_output(), comp.get_next_output()
if tile == 2: # Block
blocks += 1
except: break # The computer raises an Exception when trying to get an input after it's done
print(blocks)
### Part 2:
comp = from_file("input/day13.txt")
comp.code[0] = 2
score = 0
ball_x = None
paddle_x = None
def get_joystick_input():
if ball_x > paddle_x:
return 1 # Move right
elif ball_x < paddle_x:
return -1 # Move left
else:
return 0 # Dont move
comp.set_inputs([get_joystick_input])
while True:
try:
x, y, tile = comp.get_next_output(), comp.get_next_output(), comp.get_next_output()
if x == -1 and y == 0:
score = tile
elif tile == 3: # Paddle
paddle_x = x
elif tile == 4: # Ball
ball_x = x
except: break
print(score)