summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2021-12-04 13:47:35 +0000
committerTomasz Kramkowski <tk@the-tk.com>2021-12-04 13:47:35 +0000
commitc094a4220f696dbdbddf15364f17375738f69814 (patch)
treefecb33a4950d156077256259d0baba7519ee2d83
parent499f45e61349a7d2f6ddbd0c9b69ca79cd530d1c (diff)
downloadaoc2021-c094a4220f696dbdbddf15364f17375738f69814.tar.gz
aoc2021-c094a4220f696dbdbddf15364f17375738f69814.tar.xz
aoc2021-c094a4220f696dbdbddf15364f17375738f69814.zip
day 4: only check {col,row}_hits for hit col/row
-rw-r--r--4.py11
1 files 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':