-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathday19.py
executable file
·70 lines (52 loc) · 1.27 KB
/
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
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
67
68
69
#!/usr/bin/env python3
from utils.all import *
fin = advent.get_input()
# eprint(*fin, sep='')
timer_start()
##################################################
from lib.intcode import IntcodeVM
prog = read_ints(fin)
vm = IntcodeVM(prog)
n = 0
for i in range(50):
for j in range(50):
out = vm.run([i, j], n_out=1)
if not out:
break
if out[0] == 1:
n += 1
# print(n)
advent.submit_answer(1, n)
# PART 2:
# Visualize, copy in text editor and solve by hand
# using a regex: (1{100}.+\n){100}
starty, startx = 350, 1050 + (150 - 127)
width, height = 150, 200
# grid = [[-1] * width for _ in range(height)]
# foundx = 0
# for x in range(width):
# log('> {}\r ', x)
# n = 0
# for y in range(height):
# res = intcode_oneshot(prog, [x+startx, y+starty])[0]
# n += res
# grid[y][x] = res
# if n == 134:
# if foundx == 0:
# foundx = x
# conv = dict(zip(range(-1, 100), '! #'))
# vizgrid = []
# for l in grid:
# a = ''.join(map(lambda v: conv.get(v, '?'), l))
# a = ''.join(map(str, l))
# vizgrid.append(a)
# dump_iterable(vizgrid)
foundx = 0
x = foundx + startx
y = starty + 61
answer = x * 10000 + y
# 13440699 wrong (1195, 549)
# 11950549 wrong (1344, 699) of course...
# 10670533 wrong (1067, 533)
# 10730533 wrong (1073, 533)
advent.submit_answer(2, answer)