-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday_8.py
33 lines (30 loc) · 1.01 KB
/
day_8.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
#coding=utf8
def part_1(input, wide, tall):
min_0 = len(input); output = 0
for i in range(0, len(input), wide * tall):
layer = input[i: i + wide * tall]
num_0 = layer.count('0')
num_1 = layer.count('1')
num_2 = layer.count('2')
if num_0 < min_0:
min_0 = num_0
output = num_1 * num_2
return output
def part_2(input, wide, tall):
output = [2] * (wide * tall)
for i in range(0, len(input), wide * tall):
layer = input[i: i + wide * tall]
for j in range(len(output)):
if output[j] in ['0', '1']:
continue
if layer[j] in ['0', '1']:
output[j] = layer[j]
for i in range(0, len(output), wide):
print (''.join(output[i: i+wide]).replace('1', '*').replace('0', ' '))
return output
if __name__ == '__main__':
with open('day_8.txt') as file:
input = file.read().strip()
wide = 25; tall = 6
#print (part_1(input, wide, tall))
part_2(input, wide, tall)