day 3 part 2
This commit is contained in:
parent
543b0b7e82
commit
d97c512816
@ -2,6 +2,8 @@ import matrix
|
|||||||
import shared
|
import shared
|
||||||
import itertools
|
import itertools
|
||||||
import functools
|
import functools
|
||||||
|
from pprint import pprint
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
SYMBOLS="*%@#+-/$=&"
|
SYMBOLS="*%@#+-/$=&"
|
||||||
|
|
||||||
@ -49,13 +51,23 @@ def process_number(mx, coords, num):
|
|||||||
|
|
||||||
# @shared.profile
|
# @shared.profile
|
||||||
def part2(mat):
|
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)
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user