|
|
@ -18,7 +18,7 @@ class Diagnostics: |
|
|
|
self.report = report |
|
|
|
|
|
|
|
|
|
|
|
def power_usage(self) -> None: |
|
|
|
def calc_power_usage(self) -> None: |
|
|
|
most_common = self.commonality(self.report) |
|
|
|
gamma = epsilon = "" |
|
|
|
for common in most_common: |
|
|
@ -34,7 +34,7 @@ class Diagnostics: |
|
|
|
return gamma * epsilon |
|
|
|
|
|
|
|
|
|
|
|
def calculate_oxygen_generator_rating(self, inputs) -> int: |
|
|
|
def calc_oxygen_generator_rating(self, inputs) -> int: |
|
|
|
""" |
|
|
|
Bit Criteria: |
|
|
|
Most common value in current bit position |
|
|
@ -52,12 +52,12 @@ class Diagnostics: |
|
|
|
return int(report[0], 2) |
|
|
|
|
|
|
|
if len(report) > 1: # May not be necessary |
|
|
|
report = self.calculate_oxygen_generator_rating(report) |
|
|
|
report = self.calc_oxygen_generator_rating(report) |
|
|
|
|
|
|
|
return int(report[0], 2) |
|
|
|
|
|
|
|
|
|
|
|
def calculate_co2_scrubber_rating(self, inputs) -> int: |
|
|
|
def calc_co2_scrubber_rating(self, inputs) -> int: |
|
|
|
""" |
|
|
|
Bit Criteria: |
|
|
|
Least common value in current position |
|
|
@ -75,16 +75,17 @@ class Diagnostics: |
|
|
|
return int(report[0], 2) |
|
|
|
|
|
|
|
if len(report) > 1: # May not be necessary |
|
|
|
report = self.calculate_oxygen_generator_rating(report) |
|
|
|
report = self.calc_oxygen_generator_rating(report) |
|
|
|
|
|
|
|
return int(report[0], 2) |
|
|
|
|
|
|
|
|
|
|
|
def calculate_life_support_rating(self) -> int: |
|
|
|
oxygen_generator_rating = self.calculate_oxygen_generator_rating(self.report) |
|
|
|
co2_scrubber_rating = self.calculate_co2_scrubber_rating(self.report) |
|
|
|
def calc_life_support_rating(self) -> int: |
|
|
|
oxygen_generator_rating = self.calc_oxygen_generator_rating(self.report) |
|
|
|
co2_scrubber_rating = self.calc_co2_scrubber_rating(self.report) |
|
|
|
return oxygen_generator_rating * co2_scrubber_rating |
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
def commonality(report: List[int]) -> List[Dict[str, int]]: |
|
|
|
common_counts = [] |
|
|
@ -108,14 +109,14 @@ class Diagnostics: |
|
|
|
return common |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def part1(inputs: List[int]) -> int: |
|
|
|
diag = Diagnostics(inputs) |
|
|
|
return diag.power_usage() |
|
|
|
return diag.calc_power_usage() |
|
|
|
|
|
|
|
|
|
|
|
def part2(inputs: List[int]) -> int: |
|
|
|
diag = Diagnostics(inputs) |
|
|
|
return diag.calculate_life_support_rating() |
|
|
|
return diag.calc_life_support_rating() |
|
|
|
|
|
|
|
|
|
|
|
def parse(inputs: str) -> List[int]: |
|
|
|