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.

24 lines
540 B

f = open ('input3.txt', 'r')
inp = f.readlines()
ones = [0] * 12
zeroes = [0] * 12
gamma = 0
epsilon = 0
for i in range(len(inp)):
inp[i] = inp[i].strip()
for line in inp:
for i in range(len(line)):
if line[i] == '1':
ones[i] += 1
if line[i] == '0':
zeroes[i] += 1
for i in range(len(ones)):
if ones[i] < zeroes[i]:
gamma <<= 1
epsilon = (epsilon << 1) + 1
else:
gamma = (gamma << 1) + 1
epsilon <<= 1
print(epsilon * gamma)
print(gamma)
print(epsilon)