streamlined 3a

master
kwout 2 years ago
parent e491f7718e
commit 36af1cd090
  1. 21
      day3/3a.py

@ -1,25 +1,22 @@
lines = open("input.txt", 'r').read().splitlines() lines = open("input.txt", 'r').read().splitlines()
leng = len(lines) leng = len(lines)
count = [0] * len(lines[0]) bits = len(lines[0])
count = [0] * bits
for s in lines: for s in lines:
for i in range(0, len(s)): for i in range(0, bits):
if bool(int(s[i])): if bool(int(s[i])):
count[i] += 1 count[i] += 1
s = "" gama = 0
t = "" epsi = 0
print(count) print(count)
for i in count: for i in range(0, bits):
if i > leng/2: if count[i] > leng/2:
s += "1" gama += 2**(bits-i-1)
t += "0"
else: else:
s += "0" epsi += 2**(bits-i-1)
t += "1"
gama = int(s, 2)
epsi = int(t, 2)
print(gama) print(gama)
print(epsi) print(epsi)
print(gama*epsi) print(gama*epsi)

Loading…
Cancel
Save