-
Notifications
You must be signed in to change notification settings - Fork 17
/
day13.py
executable file
·98 lines (67 loc) · 1.38 KB
/
day13.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env python3
from utils.all import *
advent.setup(2021, 13)
if 'debug' not in map(str.lower, sys.argv):
fin = advent.get_input()
else:
fin = io.StringIO('''\
0,0
2,2
fold along y=1
''')
eprint(*fin, sep='', end='----- end of input -----\n\n'); fin.seek(0, 0)
timer_start()
ans = 0
try: ints = read_ints(fin); fin.seek(0, 0)
except: pass
try: lines = get_lines(fin); fin.seek(0, 0)
except: pass
try: mat = read_char_matrix(fin); fin.seek(0, 0)
except: pass
sheet = {}
for l in fin:
l = l.strip()
if not l:
break
x, y = map(int, l.split(','))
sheet[x, y] = 1
foldx = int(fin.readline().split('=')[1])
new = {}
for x, y in sheet:
if x > foldx:
x = foldx - abs(x - foldx)
new[x, y] = 1
ans = len(new)
advent.print_answer(1, ans)
# wait('Submit? ')
# advent.submit_answer(1, ans)
sheet = new
for line in fin:
line = line.strip()
if not line:
continue
if 'x=' in line:
foldx = int(line.split('=')[1])
new = {}
for x, y in sheet:
if x > foldx:
x = foldx - abs(x - foldx)
new[x, y] = 1
sheet = new
else:
foldy = int(line.split('=')[1])
new = {}
for x, y in sheet:
if y > foldy:
y = foldy - abs(y - foldy)
new[x, y] = 1
sheet = new
maxx = max(map(itemgetter(0), sheet))
maxy = max(map(itemgetter(1), sheet))
for y in range(maxy+1):
for x in range(maxx+1):
if (x, y) in sheet:
log('#')
else:
log(' ')
log('\n')