From 31995dca1da963471328125884989a53a535bffd Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Sat, 4 Dec 2021 14:17:30 +0000 Subject: day 4: Remove need to keep width and height --- 4.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/4.py b/4.py index c26629b..e85f358 100644 --- a/4.py +++ b/4.py @@ -1,18 +1,16 @@ from utils import open_day class Board: - width: int - height: int 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: - self.width = len(cells[0]) - self.height = len(cells) - self.col_hits = [0] * self.width - self.row_hits = [0] * self.height + width: int = len(cells[0]) + height: int = len(cells) + self.col_hits = [height] * width + self.row_hits = [width ] * height self.nums = dict() for y, row in enumerate(cells): for x, cell in enumerate(row): @@ -22,13 +20,13 @@ class Board: def call(self, num: int) -> None: pos: tuple[int, int] = self.nums.get(num) if pos is None: return - self.col_hits[pos[0]] += 1 - self.row_hits[pos[1]] += 1 + self.col_hits[pos[0]] -= 1 + self.row_hits[pos[1]] -= 1 self.unmarked_sum -= num self.has_bingo = ( self.has_bingo or - self.col_hits[pos[0]] == self.height or - self.row_hits[pos[1]] == self.width + not self.col_hits[pos[0]] or + not self.row_hits[pos[1]] ) @staticmethod def from_string(s: str) -> 'Board': -- cgit v1.2.3-54-g00ecf