diff --git a/puzzles/day03.py b/puzzles/day03.py index eb7c82f..d1598de 100644 --- a/puzzles/day03.py +++ b/puzzles/day03.py @@ -11,13 +11,13 @@ from typing import Dict, List, Tuple from collections import defaultdict + class Diagnostics: report = None def __init__(self, report: List[int]) -> None: self.report = report - def calc_power_usage(self) -> None: most_common = self.commonality(self.report) gamma = epsilon = "" @@ -33,7 +33,6 @@ class Diagnostics: epsilon = int(epsilon, 2) return gamma * epsilon - def calc_oxygen_generator_rating(self, inputs) -> int: """ Bit Criteria: @@ -45,18 +44,20 @@ class Diagnostics: for column in range(len(report[0])): most_common = self.commonality(report) for binary in list(report): - if (int(binary[column]) != most_common[column] and most_common[column] != 2) or (most_common[column] == 2 and binary[column] != "1"): + if ( + int(binary[column]) != most_common[column] + and most_common[column] != 2 + ) or (most_common[column] == 2 and binary[column] != "1"): report.remove(binary) if len(report) == 1: return int(report[0], 2) - if len(report) > 1: # May not be necessary + if len(report) > 1: # May not be necessary report = self.calc_oxygen_generator_rating(report) return int(report[0], 2) - def calc_co2_scrubber_rating(self, inputs) -> int: """ Bit Criteria: @@ -68,24 +69,24 @@ class Diagnostics: for column in range(len(report[0])): most_common = self.commonality(report) for binary in list(report): - if (int(binary[column]) == most_common[column]) or (most_common[column] == 2 and binary[column] != "0"): + if (int(binary[column]) == most_common[column]) or ( + most_common[column] == 2 and binary[column] != "0" + ): report.remove(binary) if len(report) == 1: return int(report[0], 2) - if len(report) > 1: # May not be necessary + if len(report) > 1: # May not be necessary report = self.calc_oxygen_generator_rating(report) return int(report[0], 2) - 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]]: num_1 = defaultdict(int) @@ -94,10 +95,10 @@ class Diagnostics: num_1[column] += int(bit) common = [] - half_total = len(report)/2 + half_total = len(report) / 2 for count in num_1.values(): if count == half_total: - common.append(2) # Indicating equally common + common.append(2) # Indicating equally common elif count > half_total: common.append(1) else: