my advent of code 2021 solutions
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.0 KiB

f = open ('input3.txt', 'r')
inp = f.readlines()
oxy = 0
co = 0
for i in range(len(inp)):
inp[i] = inp[i].strip()
inp2 = inp
for i in range(12):
if len(inp) == 1:
break
zero = 0
one = 0
for line in inp:
if line[i] == '0':
zero += 1
else:
one += 1
if zero <= one:
inp = list(filter(lambda line: line[i] == '1', inp))
else:
inp = list(filter(lambda line: line[i] == '0', inp))
for i in range(12):
if len(inp2) == 1:
break
zero = 0
one = 0
for line in inp2:
if line[i] == '0':
zero += 1
else:
one += 1
if zero <= one:
inp2 = list(filter(lambda line: line[i] == '0', inp2))
else:
inp2 = list(filter(lambda line: line[i] == '1', inp2))
print(inp, " ", inp2)
for i in range(12):
if inp[0][i] == '1':
oxy = (oxy << 1) + 1
else:
oxy <<= 1
if inp2[0][i] == '1':
co = (co << 1) + 1
else:
co <<= 1
print(co," ", oxy)
print(co * oxy)