day 3 part 2

This commit is contained in:
Tyrel Souza 2023-12-03 16:18:14 -05:00
parent 543b0b7e82
commit d97c512816
No known key found for this signature in database
GPG Key ID: F3614B02ACBE438E
1 changed files with 18 additions and 6 deletions

View File

@ -2,6 +2,8 @@ import matrix
import shared
import itertools
import functools
from pprint import pprint
from collections import defaultdict
SYMBOLS="*%@#+-/$=&"
@ -49,13 +51,23 @@ def process_number(mx, coords, num):
# @shared.profile
def part2(mat):
print(matrix.ppmx(mat, pad=False))
_nums = get_all_numbers_and_starting_coords(mat)
nums = []
#get_row_coords(*coords, len(num))
splats = matrix.find_in_matrix(mat, "*", False)
print(splats)
_nums = get_all_numbers_and_starting_coords(mat)
symbols = defaultdict(list)
nums = get_all_numbers_and_starting_coords(mat)
for coords, num in nums:
valid, sc = process_number(mat, coords, num)
if valid:
symbols[(sc[0]['r'],sc[0]['c'])].append(num)
total = 0
for splat in splats:
neighbors = symbols[splat]
if len(neighbors) != 2:
continue
ratio = int(neighbors[0]) * int(neighbors[1])
total += ratio
print(total)