19 lines
462 B
Python
19 lines
462 B
Python
#!/usr/bin/env python3
|
|
from collections import Counter
|
|
|
|
|
|
def find(is_lowest):
|
|
lines = [x.strip() for x in open("input.txt")]
|
|
for bit in range(12):
|
|
common = (max if is_lowest else min)(
|
|
map(lambda x: x[::-1], Counter(s[bit] for s in lines).items())
|
|
)[1]
|
|
lines = [s for s in lines if s[bit] == common]
|
|
return lines
|
|
|
|
|
|
gamma = int(''.join(find(False)), 2)
|
|
epsilon = int(''.join(find(True)), 2)
|
|
|
|
print(gamma * epsilon)
|