|
@ -11,13 +11,13 @@ from typing import Dict, List, Tuple |
|
|
|
|
|
|
|
|
from collections import defaultdict |
|
|
from collections import defaultdict |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Diagnostics: |
|
|
class Diagnostics: |
|
|
report = None |
|
|
report = None |
|
|
|
|
|
|
|
|
def __init__(self, report: List[int]) -> None: |
|
|
def __init__(self, report: List[int]) -> None: |
|
|
self.report = report |
|
|
self.report = report |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def calc_power_usage(self) -> None: |
|
|
def calc_power_usage(self) -> None: |
|
|
most_common = self.commonality(self.report) |
|
|
most_common = self.commonality(self.report) |
|
|
gamma = epsilon = "" |
|
|
gamma = epsilon = "" |
|
@ -33,7 +33,6 @@ class Diagnostics: |
|
|
epsilon = int(epsilon, 2) |
|
|
epsilon = int(epsilon, 2) |
|
|
return gamma * epsilon |
|
|
return gamma * epsilon |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def calc_oxygen_generator_rating(self, inputs) -> int: |
|
|
def calc_oxygen_generator_rating(self, inputs) -> int: |
|
|
""" |
|
|
""" |
|
|
Bit Criteria: |
|
|
Bit Criteria: |
|
@ -45,18 +44,20 @@ class Diagnostics: |
|
|
for column in range(len(report[0])): |
|
|
for column in range(len(report[0])): |
|
|
most_common = self.commonality(report) |
|
|
most_common = self.commonality(report) |
|
|
for binary in list(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) |
|
|
report.remove(binary) |
|
|
|
|
|
|
|
|
if len(report) == 1: |
|
|
if len(report) == 1: |
|
|
return int(report[0], 2) |
|
|
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) |
|
|
report = self.calc_oxygen_generator_rating(report) |
|
|
|
|
|
|
|
|
return int(report[0], 2) |
|
|
return int(report[0], 2) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def calc_co2_scrubber_rating(self, inputs) -> int: |
|
|
def calc_co2_scrubber_rating(self, inputs) -> int: |
|
|
""" |
|
|
""" |
|
|
Bit Criteria: |
|
|
Bit Criteria: |
|
@ -68,24 +69,24 @@ class Diagnostics: |
|
|
for column in range(len(report[0])): |
|
|
for column in range(len(report[0])): |
|
|
most_common = self.commonality(report) |
|
|
most_common = self.commonality(report) |
|
|
for binary in list(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) |
|
|
report.remove(binary) |
|
|
|
|
|
|
|
|
if len(report) == 1: |
|
|
if len(report) == 1: |
|
|
return int(report[0], 2) |
|
|
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) |
|
|
report = self.calc_oxygen_generator_rating(report) |
|
|
|
|
|
|
|
|
return int(report[0], 2) |
|
|
return int(report[0], 2) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def calc_life_support_rating(self) -> int: |
|
|
def calc_life_support_rating(self) -> int: |
|
|
oxygen_generator_rating = self.calc_oxygen_generator_rating(self.report) |
|
|
oxygen_generator_rating = self.calc_oxygen_generator_rating(self.report) |
|
|
co2_scrubber_rating = self.calc_co2_scrubber_rating(self.report) |
|
|
co2_scrubber_rating = self.calc_co2_scrubber_rating(self.report) |
|
|
return oxygen_generator_rating * co2_scrubber_rating |
|
|
return oxygen_generator_rating * co2_scrubber_rating |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
@staticmethod |
|
|
def commonality(report: List[int]) -> List[Dict[str, int]]: |
|
|
def commonality(report: List[int]) -> List[Dict[str, int]]: |
|
|
num_1 = defaultdict(int) |
|
|
num_1 = defaultdict(int) |
|
@ -94,10 +95,10 @@ class Diagnostics: |
|
|
num_1[column] += int(bit) |
|
|
num_1[column] += int(bit) |
|
|
|
|
|
|
|
|
common = [] |
|
|
common = [] |
|
|
half_total = len(report)/2 |
|
|
|
|
|
|
|
|
half_total = len(report) / 2 |
|
|
for count in num_1.values(): |
|
|
for count in num_1.values(): |
|
|
if count == half_total: |
|
|
if count == half_total: |
|
|
common.append(2) # Indicating equally common |
|
|
|
|
|
|
|
|
common.append(2) # Indicating equally common |
|
|
elif count > half_total: |
|
|
elif count > half_total: |
|
|
common.append(1) |
|
|
common.append(1) |
|
|
else: |
|
|
else: |
|
|