|
|
@ -11,27 +11,36 @@ from typing import List, Tuple |
|
|
|
|
|
|
|
from collections import defaultdict |
|
|
|
|
|
|
|
def part1(inputs: List[int]) -> int: |
|
|
|
num_1 = defaultdict(int) |
|
|
|
for line in inputs: |
|
|
|
for index, value in enumerate(line): |
|
|
|
num_1[index] += int(value) |
|
|
|
|
|
|
|
total = len(inputs) |
|
|
|
gamma = epsilon = "" |
|
|
|
for value in num_1.values(): |
|
|
|
if value > (total/2): |
|
|
|
gamma += "1" |
|
|
|
epsilon += "0" |
|
|
|
else: |
|
|
|
gamma += "0" |
|
|
|
epsilon += "1" |
|
|
|
|
|
|
|
gamma = int(gamma, 2) |
|
|
|
epsilon = int(epsilon, 2) |
|
|
|
power = gamma * epsilon |
|
|
|
return power |
|
|
|
class Submarine: |
|
|
|
gamma: int = 0 |
|
|
|
epsilon: int = 0 |
|
|
|
power: int = 0 |
|
|
|
|
|
|
|
def decode_report(self, report: List[int]) -> None: |
|
|
|
num_1 = defaultdict(int) |
|
|
|
for binary in report: |
|
|
|
for index, bit in enumerate(binary): |
|
|
|
num_1[index] += int(bit) |
|
|
|
|
|
|
|
total = len(report) |
|
|
|
gamma = epsilon = "" |
|
|
|
for binary in num_1.values(): |
|
|
|
if binary > (total/2): |
|
|
|
gamma += "1" |
|
|
|
epsilon += "0" |
|
|
|
else: |
|
|
|
gamma += "0" |
|
|
|
epsilon += "1" |
|
|
|
|
|
|
|
self.gamma = int(gamma, 2) |
|
|
|
self.epsilon = int(epsilon, 2) |
|
|
|
self.power = self.gamma * self.epsilon |
|
|
|
|
|
|
|
|
|
|
|
def part1(inputs: List[int]) -> int: |
|
|
|
sub = Submarine() |
|
|
|
sub.decode_report(inputs) |
|
|
|
return sub.power |
|
|
|
|
|
|
|
def part2(inputs: List[int]) -> int: |
|
|
|
return False |
|
|
|