summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2021-12-04 14:17:30 +0000
committerTomasz Kramkowski <tk@the-tk.com>2021-12-04 14:17:30 +0000
commit31995dca1da963471328125884989a53a535bffd (patch)
tree525ea38a099b068e7087ea717b105ab5c1ed2b38
parent7a95602beae551e8a1af76aa2b4949ce358dbe53 (diff)
downloadaoc2021-31995dca1da963471328125884989a53a535bffd.tar.gz
aoc2021-31995dca1da963471328125884989a53a535bffd.tar.xz
aoc2021-31995dca1da963471328125884989a53a535bffd.zip
day 4: Remove need to keep width and height
-rw-r--r--4.py18
1 files 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':