Nick's Advent of Code efforts
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.
 
 
 
 
 

28 lines
621 B

#!/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)