-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday3_part2.py
57 lines (39 loc) · 1.06 KB
/
day3_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
data = [i.strip('\n') for i in open('day3-input.txt','r').readlines()]
oxyKeepers = data
co2Keepers = data
# Iterate filtering out oxygen values
for x, point in enumerate(data[0]):
counter = [0,0]
for i, item in enumerate(oxyKeepers):
if int(item[x]) == 0:
counter[0] += 1
elif int(item[x]) ==1:
counter[1] += 1
num = 0
if counter[1] >= counter[0]:
num = 1
temp = []
for i, item in enumerate(oxyKeepers):
if int(item[x]) == int(num):
temp.append(item)
oxyKeepers = temp if len(temp) > 0 else oxyKeepers
# Iterate filtering out co2 values
for x, point in enumerate(data[0]):
counter = [0,0]
for i, item in enumerate(co2Keepers):
if int(item[x]) == 0:
counter[0] += 1
elif int(item[x]) ==1:
counter[1] += 1
num = 0
if counter[1] >= counter[0]:
num = 0
elif counter[0] > counter[1]:
num = 1
temp = []
for i, item in enumerate(co2Keepers):
if int(item[x]) == int(num):
temp.append(item)
co2Keepers = temp if len(temp) > 0 else co2Keepers
print(oxyKeepers, co2Keepers)
print(int(oxyKeepers[0],2) * int(co2Keepers[0],2))