diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2021-12-04 14:17:30 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2021-12-04 14:17:30 +0000 |
commit | 31995dca1da963471328125884989a53a535bffd (patch) | |
tree | 525ea38a099b068e7087ea717b105ab5c1ed2b38 | |
parent | 7a95602beae551e8a1af76aa2b4949ce358dbe53 (diff) | |
download | aoc2021-31995dca1da963471328125884989a53a535bffd.tar.gz aoc2021-31995dca1da963471328125884989a53a535bffd.tar.xz aoc2021-31995dca1da963471328125884989a53a535bffd.zip |
day 4: Remove need to keep width and height
-rw-r--r-- | 4.py | 18 |
1 files changed, 8 insertions, 10 deletions
@@ -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': |