diff --git a/day3/day3.py b/day3/day3.py index c0f1c0f..ce305cd 100644 --- a/day3/day3.py +++ b/day3/day3.py @@ -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] diff --git a/day3/test_input2.txt b/day3/test_input2.txt deleted file mode 100644 index 8b13789..0000000 --- a/day3/test_input2.txt +++ /dev/null @@ -1 +0,0 @@ -