2021: day3p1
This commit is contained in:
1000
2021/03/input
Normal file
1000
2021/03/input
Normal file
File diff suppressed because it is too large
Load Diff
28
2021/03/part1
Executable file
28
2021/03/part1
Executable file
@@ -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)
|
||||
|
Reference in New Issue
Block a user