From c094a4220f696dbdbddf15364f17375738f69814 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Sat, 4 Dec 2021 13:47:35 +0000 Subject: day 4: only check {col,row}_hits for hit col/row --- 4.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/4.py b/4.py index 0d44156..1373ca3 100644 --- a/4.py +++ b/4.py @@ -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': -- cgit v1.2.3-54-g00ecf