-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD3_P2.py
28 lines (21 loc) · 827 Bytes
/
D3_P2.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
import numpy as np
def find_parameter(set, most_common:bool):
col = 0
while set.shape[0] != 1:
print(set)
row_number = set.shape[0]
if most_common:
criteria = round(sum(set[:,col])/row_number + 0.001) #calculate most common value in column
else:
criteria = round(1 - sum(set[:,col])/row_number) #calculate least common value in column
set = set[np.where(set[:,col] == criteria)]
col += 1
print(set)
return int("".join([str(int(x)) for x in set[0]]), 2)
with open("D3_input.txt", 'r') as input_f:
input = np.array([list(x.replace('\n','')) for x in input_f.readlines()]).astype(np.int)
oxygen = find_parameter(input, True)
co2 = find_parameter(input, False)
print(oxygen)
print(co2)
print(oxygen*co2)