-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path08.py
36 lines (22 loc) · 838 Bytes
/
08.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 lib import *
input = read_input(2016, 8)
T = lambda g: [*map(list, zip(*g))]
def rotate(g, a, b):
g[a] = [g[a][(i - b) % len(g[a])] for i in range(len(g[a]))]
return g
grid = [[0 for _ in range(50)] for _ in range(6)]
for line in input.splitlines():
if match := re.match(r"^rect (\d+)x(\d+)$", line):
w, h = map(int, match.groups())
for i in range(h):
for j in range(w):
grid[i][j] = 1
elif match := re.match(r"^rotate row y=(\d+) by (\d+)$", line):
a, b = map(int, match.groups())
rotate(grid, a, b)
elif match := re.match(r"^rotate column x=(\d+) by (\d+)$", line):
a, b = map(int, match.groups())
grid = T(rotate(T(grid), a, b))
print(sum(map(sum, grid)))
for line in grid:
print("".join(" #"[c] * 2 for c in line))