Skip to content

Commit

Permalink
part2 finished! the solution is n^2, but could be optimized by adding…
Browse files Browse the repository at this point in the history
… more limits around filtering for which enginer parts are important/.
  • Loading branch information
aws-donco committed Dec 3, 2023
1 parent f5e63a1 commit 8d17a58
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
33 changes: 28 additions & 5 deletions day03.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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'
Expand Down Expand Up @@ -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}')

Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 8d17a58

Please sign in to comment.