From dbc4d7d2b0faf3090da18be389b5701da5c9797a Mon Sep 17 00:00:00 2001 From: Donald Cowart Date: Sun, 3 Dec 2023 15:28:14 +0000 Subject: [PATCH] work on part 1 still, added some coloring to the output as it reads numbers and symbols. --- day03.py | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/day03.py b/day03.py index d8d6832..b6f63d9 100644 --- a/day03.py +++ b/day03.py @@ -9,6 +9,17 @@ 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' + OKCYAN = '\033[96m' + OKGREEN = '\033[92m' + WARNING = '\033[93m' + FAIL = '\033[91m' + ENDC = '\033[0m' + BOLD = '\033[1m' + UNDERLINE = '\033[4m' + def part01(day_input): # not working yet. @@ -30,15 +41,25 @@ def part01(day_input): else: current_part.part_number += line[idx] found_part = True + else: if found_part: engine_parts.append(current_part) current_part = EnginePart(part_number=None, part_location_idx=None, part_location_line=None, part_symbol=None, part_sym_line=None, part_sym_idx=None) found_part = False + if found_part: + print(f'{bcolors.OKBLUE}{line[idx]}{bcolors.ENDC}', end='') + else: + if line[idx] != '.': + print(f'{bcolors.OKGREEN}{line[idx]}{bcolors.ENDC}', end='') + else: + print(f'{line[idx]}', end='') + print('') line_number += 1 ep_index = 0 + # last_line=0 for ep in engine_parts: # having found all engine parts, search for symbols around the part number starting_line = ep.part_location_line @@ -50,30 +71,30 @@ def part01(day_input): line_above = 0 line_below = starting_line + 1 if line_below >= len(day_input): - line_below = line_below - 1 + line_below = starting_line col_before = starting_idx - 1 if col_before < 0: col_before = 0 col_after = starting_idx + len(ep.part_number) + 1 - if col_after > len(day_input[starting_line]): - col_after = col_after - 1 + if col_after >= len(day_input[starting_line]): + col_after = len(day_input[starting_line]) for curr_col in range(col_before, col_after): line_above_ch = day_input[line_above][curr_col] line_curr_ch = day_input[starting_line][curr_col] line_below_ch = day_input[line_below][curr_col] - if line_above_ch.isdigit() is False and line_above_ch != '.': + if not line_above_ch.isdigit() and line_above_ch != '.': engine_parts[ep_index].part_symbol = line_above_ch engine_parts[ep_index].part_sym_line = line_above engine_parts[ep_index].part_sym_idx = curr_col break - if line_curr_ch.isdigit() is False and line_curr_ch != '.': + if not line_curr_ch.isdigit() and line_curr_ch != '.': engine_parts[ep_index].part_symbol = line_curr_ch engine_parts[ep_index].part_sym_line = starting_line engine_parts[ep_index].part_sym_idx = curr_col break - if line_below_ch.isdigit() is False and line_below_ch != '.': + if not line_below_ch.isdigit() and line_below_ch != '.': engine_parts[ep_index].part_symbol = line_below_ch engine_parts[ep_index].part_sym_line = line_below engine_parts[ep_index].part_sym_idx = curr_col @@ -83,8 +104,10 @@ def part01(day_input): part_sum = 0 for ep in engine_parts: if ep.part_symbol is not None: + # 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(part_sum)