tidy up day 3

This commit is contained in:
Dmitry Fedotov
2023-12-10 20:29:23 +03:00
parent f01e786713
commit 9c9e16fbe4
2 changed files with 13 additions and 4 deletions

View File

@@ -39,13 +39,23 @@ class Scheme(object):
for xadd in [-1, 0, 1]:
x_, y_ = y + yadd, x + xadd
if self._isdigit(x_, y_):
# this is suboptimal because we will process the
# numeral adjacent to a symbol three times at max
# like in the following case
# ...*...
# ..123..
# however this saves some lines of code.
# we'll just use memoization with a dict to make sure
# we don't add the same numeral more than once
num, coords = self._extend_digit_to_numeral(x_, y_)
# just put it in a map if we found a digit
# of the same numeral
tmp[coords] = num
return list(tmp.values())
def _extend_digit_to_numeral(self, y, x) -> int:
def _extend_digit_to_numeral(self, y, x) -> (int, tuple):
'''
this returns the numeral itself plus coordinates where the numeral
has been found (y, x1..xn)
'''
found_digit = self.grid[y][x]
x_array = [x]

View File

@@ -1 +0,0 @@