2021: day3p1

main
Nick Thomas 1 year ago
parent ac039d70e3
commit e0dabfc0a1

File diff suppressed because it is too large Load Diff

@ -0,0 +1,28 @@
#!/usr/bin/env python
gamma = 0
epsilon = 0
with open('input') as f:
total = 0
g_counts = [0,0,0,0,0,0,0,0,0,0,0,0]
e_counts = [0,0,0,0,0,0,0,0,0,0,0,0]
for line in f:
total += 1
for idx, chr in enumerate(line[0:12]):
if chr == '1':
g_counts[idx]+=1
else:
e_counts[idx]+=1
target = total / 2
for idx, val in enumerate(g_counts):
if val > target:
gamma += (1 << (11-idx))
for idx, val in enumerate(e_counts):
if val > target:
epsilon += (1 << (11-idx))
print(gamma * epsilon)
Loading…
Cancel
Save