diff options
-rw-r--r-- | 4.py | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -4,7 +4,6 @@ class Board: col_hits: list[int] row_hits: list[int] has_bingo: bool - unmarked_sum: int nums: dict[int, tuple[int, int]] def __init__(self, cells: list[list[int]]) -> None: width: int = len(cells[0]) @@ -15,19 +14,20 @@ class Board: for y, row in enumerate(cells): for x, cell in enumerate(row): self.nums[cell] = (x, y) - self.unmarked_sum = sum(self.nums.keys()) self.has_bingo = False def call(self, num: int) -> None: - pos: tuple[int, int] = self.nums.get(num) + pos: tuple[int, int] | None = self.nums.pop(num, None) if pos is None: return self.col_hits[pos[0]] -= 1 self.row_hits[pos[1]] -= 1 - self.unmarked_sum -= num self.has_bingo = ( self.has_bingo or not self.col_hits[pos[0]] or not self.row_hits[pos[1]] ) + @property + def unmarked_sum(self) -> int: + return sum(self.nums.keys()) @staticmethod def from_string(s: str) -> 'Board': return Board([[int(n) for n in l.split()] for l in s.split('\n')]) |