-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday13a.py
36 lines (29 loc) · 840 Bytes
/
day13a.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
from utilities import *
import numpy as np
rows = parse_01()
arrs = []
curr_arr = []
for row in rows:
if row == []:
arrs.append(np.array(curr_arr))
curr_arr = []
else:
curr_arr.append(row)
arrs.append(np.array(curr_arr))
def get_reflection(a):
for r in range(1, len(a)):
reflected_len = min(r, len(a) - r)
ref_top = a[r - reflected_len: r, :]
ref_bottom = a[r: r + reflected_len, :]
if np.all(ref_top == np.flipud(ref_bottom)):
return 100 * r
for c in range(1, len(a[0])):
reflected_len = min(c, len(a[0]) - c)
ref_left = a[:, c - reflected_len: c]
ref_right = a[:, c: c + reflected_len]
if np.all(ref_left == np.fliplr(ref_right)):
return c
ans = 0
for a in arrs:
ans += get_reflection(a)
print(ans)