-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday14_1.py
52 lines (41 loc) · 1.14 KB
/
day14_1.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
from collections import defaultdict, deque
import time
# --- Day 12: Garden Groups ---
start_time = time.time()
is_test = False
day = 14
input_file = f'./input/day{day}{"_test" if is_test else ""}.txt'
m = 103
n = 101
times = 100
def build_grid():
return defaultdict(str) | {(i, j): 0 for i in range(m) for j in range(n)}
g = build_grid()
def sol():
robots = []
with open(input_file, 'r') as f:
for line in f.readlines():
p, v = line.split(' ')
c, r = p.split('=')[1].split(',')
vy, vx = v.split('=')[1].split(',')
robots.append((int(r), int(c), int(vy), int(vx)))
for robot in robots:
sr, sc, vy, vx = robot
er, ec = (sr + times * vx) % m, (sc + times * vy) % n
g[(er, ec)] += 1
res = defaultdict(int)
for k, v in g.items():
x, y = k
if x == m // 2 or y == n // 2 or v == 0:
continue
if x > m // 2:
x -= 1
if y > n // 2:
y -= 1
quadrant = (x // (m // 2), y // (n // 2))
res[quadrant] += v
total = 1
for v in res.values():
total *= v
print(total)
sol()