diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2021-12-04 13:47:35 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2021-12-04 13:47:35 +0000 |
commit | c094a4220f696dbdbddf15364f17375738f69814 (patch) | |
tree | fecb33a4950d156077256259d0baba7519ee2d83 | |
parent | 499f45e61349a7d2f6ddbd0c9b69ca79cd530d1c (diff) | |
download | aoc2021-c094a4220f696dbdbddf15364f17375738f69814.tar.gz aoc2021-c094a4220f696dbdbddf15364f17375738f69814.tar.xz aoc2021-c094a4220f696dbdbddf15364f17375738f69814.zip |
day 4: only check {col,row}_hits for hit col/row
-rw-r--r-- | 4.py | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -26,12 +26,15 @@ class Board: def call(self, num: int) -> None: if num not in self.nums: return pos: int = self.cells.index(num) - self.col_hits[pos % self.width] += 1 - self.row_hits[pos // self.width] += 1 + x: int = pos % self.width + y: int = pos // self.width + self.col_hits[x] += 1 + self.row_hits[y] += 1 self.unmarked_sum -= num self.has_bingo = ( - any(hits == self.height for hits in self.col_hits) or - any(hits == self.width for hits in self.row_hits) + self.has_bingo or + self.col_hits[x] == self.height or + self.row_hits[y] == self.width ) @staticmethod def from_string(s: str) -> 'Board': |