Browse Source

2021: day3p1

main
Nick Thomas 4 months ago
parent
commit
e0dabfc0a1
  1. 1000
      2021/03/input
  2. 28
      2021/03/part1

1000
2021/03/input

File diff suppressed because it is too large Load Diff

28
2021/03/part1

@ -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