[Python/2016] Move solutions into .py files

This commit is contained in:
Felix Bargfeldt 2023-10-29 12:38:12 +01:00
parent 0269ad8fc3
commit 2514b1d11f
Signed by: Defelo
GPG key ID: 2A05272471204DD3
50 changed files with 1172 additions and 3386 deletions

36
Python/2016/08.py Normal file
View file

@ -0,0 +1,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))