This repository was archived by the owner on Nov 12, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpart2.py
59 lines (40 loc) · 1.52 KB
/
part2.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
53
54
55
56
57
58
59
from __future__ import annotations
import argparse
import os.path
import support
INPUT_TXT = os.path.join(os.path.dirname(__file__), 'input.txt')
def compute(s: str) -> None:
bits = [[False] * 50 for _ in range(6)]
for line in s.replace('x=', '').replace('y=', '').splitlines():
match line.split():
case 'rect', dims:
w_s, h_s = dims.split('x')
w, h = int(w_s), int(h_s)
for x in range(w):
for y in range(h):
bits[y][x] = True
case 'rotate', 'row', y_s, _, by_s:
y, by = int(y_s), int(by_s)
row = bits[y]
newrow = row[-by:] + row[:-by]
for x, val in enumerate(newrow):
bits[y][x] = val
case 'rotate', 'column', x_s, _, by_s:
x, by = int(x_s), int(by_s)
col = [row[x] for row in bits]
newcol = col[-by:] + col[:-by]
for y, val in enumerate(newcol):
bits[y][x] = val
case unreachable:
raise AssertionError(unreachable)
for row in bits:
print(''.join('#' if val else ' ' for val in row))
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument('data_file', nargs='?', default=INPUT_TXT)
args = parser.parse_args()
with open(args.data_file) as f, support.timing():
compute(f.read())
return 0
if __name__ == '__main__':
raise SystemExit(main())