summaryrefslogtreecommitdiffstats
path: root/4.py
diff options
context:
space:
mode:
Diffstat (limited to '4.py')
-rw-r--r--4.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/4.py b/4.py
index 41dc053..ca63510 100644
--- a/4.py
+++ b/4.py
@@ -1,4 +1,4 @@
-from itertools import product, chain
+from itertools import chain
from utils import open_day
class Board:
@@ -21,17 +21,17 @@ class Board:
self.cells.append(cell)
self.has_bingo = False
def call(self, num: int):
- for y, x in product(range(self.height), range(self.width)):
- cell = self.cells[x + self.width * y]
- if cell == num:
- self.col_hits[x] += 1
- self.row_hits[y] += 1
- self.unmarked_sum -= cell
- self.has_bingo = (
- any(hits == self.height for hits in self.col_hits) or
- any(hits == self.width for hits in self.row_hits)
- )
- return
+ try:
+ pos: int = self.cells.index(num)
+ self.col_hits[pos // self.width] += 1
+ self.row_hits[pos // self.height] += 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)
+ )
+ except ValueError:
+ pass
@staticmethod
def from_string(s: str) -> 'Board':
return Board([[int(n) for n in l.split()] for l in s.split('\n')])