-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday19.py
41 lines (32 loc) · 921 Bytes
/
day19.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
from etc.intcode import IntcodeComputer
grid = {}
code = [int(x) for x in open("input/day19.txt").read().strip().split(",")]
def try_coord(x,y):
if (x,y) in grid: return grid[x,y]
comp = IntcodeComputer(code.copy())
comp.set_inputs([x, y])
res = comp.get_next_output()
grid[x,y] = res
return res
def get_next(x, y):
while try_coord(x, y+1): x += 1
return x-1, y+1
#### Part 1
for y in range(50):
on = False
for x in range(50):
val = try_coord(x,y)
grid[x,y] = val
if not on and val: on = True
if on and not val: break
print(sum(grid.values()))
#### Part 2
x = max(i for i in range(50) if grid.get((i, 49), 0))
y = 49
while True:
x, y = get_next(x, y)
if x < 100 or y < 100: continue
coords = [(x,y), (x-99,y), (x,y+99), (x-99,y+99)]
if all(try_coord(i, j) for i, j in coords):
print((x-99) * 10000 + y)
break