diff --git a/day03.py b/day03.py index 9b55a96..f534977 100644 --- a/day03.py +++ b/day03.py @@ -1,5 +1,3 @@ - - class EnginePart: def __init__(self, part_number, part_location_idx, part_location_line, part_symbol, part_sym_line, part_sym_idx): self.part_number = part_number @@ -9,6 +7,7 @@ def __init__(self, part_number, part_location_idx, part_location_line, part_symb self.part_sym_line = part_sym_line self.part_sym_idx = part_sym_idx + class bcolors: HEADER = '\033[95m' OKBLUE = '\033[94m' @@ -78,7 +77,6 @@ def part01(day_input): col_before = 0 col_after = starting_idx + len(ep.part_number) + 1 if col_after >= len(day_input[starting_line]): - col_after = len(day_input[starting_line]) print(f'{ep.part_location_line}: {ep.part_number}: {col_after}') @@ -109,9 +107,34 @@ def part01(day_input): # print(f'{ep.part_number}: {ep.part_symbol}') part_sum += int(ep.part_number) # else: - # print(f'{ep.part_number}: {ep.part_location_line}: ...') + # print(f'{ep.part_number}: {ep.part_location_line}: ...') print(part_sum) + return engine_parts + def part02(day_input): - pass + # WIP + engine_parts = part01(day_input) + + found_parts = [] + + part_sum = 0 + for ep in engine_parts: + if ep.part_symbol == '*': + # find ep with same part_sym_line & part_sym_idx & multiply... + if ep in found_parts: + continue + + found_parts.append(ep) + # O(n^2) is cruise control for cool + for epl in engine_parts: + if epl.part_sym_idx == ep.part_sym_idx \ + and epl.part_sym_line == ep.part_sym_line \ + and epl != ep \ + and epl not in found_parts: + found_parts.append(epl) + part_sum += int(ep.part_number) * int(epl.part_number) + break + + print(part_sum) diff --git a/main.py b/main.py index 4a41f99..acc4170 100644 --- a/main.py +++ b/main.py @@ -7,7 +7,7 @@ if today == '03': input_file = f'problem_inputs/day{today}_input.txt' - input_file = f'problem_inputs/day{today}_test.txt' + # input_file = f'problem_inputs/day{today}_test.txt' with open(input_file) as day_fp: day_input = day_fp.readlines() day_input = [f'{i}'.strip() for i in day_input]