-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathd8.py
65 lines (51 loc) · 1.49 KB
/
d8.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
import sys, time
from datetime import date
sys.path.extend(['..', '.'])
from collections import *
from main import run
def p1(v, log=False):
lines = v.strip().split('\n')
digits = []
for line in lines:
for ch in line.strip():
digits.append(int(ch))
W = 25 #my input
H = 6 #my input
fewest = 10**12, 0
for layer in range(0, len(digits), W * H):
lay = digits[layer: layer+W*H]
cnt = Counter(lay)
fewest = min(fewest, (cnt[0], cnt[1] * cnt[2]))
return fewest[1]
def p2(v, log=False):
lines = v.strip().split('\n')
digits = []
for line in lines:
for ch in line.strip():
digits.append(int(ch))
itr = iter(digits)
W = 25 #my input
H = 6 #my input
seen = [[-1] * W for _ in range(H)]
k = len(digits) // (W * H)
for layer in range(k):
for row in range(H):
for col in range(W):
ch = next(itr)
if seen[row][col] == -1 or seen[row][col] == 2:
seen[row][col] = ch
for row in range(H):
out =[]
for col in range(W):
if seen[row][col] == 0:
out.append('.')
else:
out.append('X')
print(''.join(map(str, out)))
return 0
def get_day():
return 8
def get_year():
return 2019
if __name__ == '__main__':
run(get_year(), get_day(), p1, p2, run_samples = False)