-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday14.py
41 lines (36 loc) · 1022 Bytes
/
day14.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
import re
from math import floor
import itertools
with open("input.txt", "r") as f:
inp = f.read().strip()
w, h = 101, 103
robots = []
for line in inp.splitlines():
ns = [int(x) for x in re.findall(r"-?\d+", line)]
robots.append(ns)
for i in itertools.count(start=1):
if i == 101:
quad = [0]*4
for r in robots:
x, y = r[0], r[1]
if x < floor(w/2) and y < floor(h/2):
quad[0] += 1
elif x > floor(w/2) and y < floor(h/2):
quad[1] += 1
elif x < floor(w/2) and y > floor(h/2):
quad[2] += 1
elif x > floor(w/2) and y > floor(h/2):
quad[3] += 1
product = 1
for c in quad:
product *= c
print(product)
m = bytearray(b"." * (w*h))
for r in robots:
r[0] = (r[0] + r[2]) % w
r[1] = (r[1] + r[3]) % h
m[r[1]*w + r[0]] = ord("*")
if b"*"*10 in m:
assert i > 101
print(i)
break