summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--4.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/4.py b/4.py
index 3cafb8b..b740d7b 100644
--- a/4.py
+++ b/4.py
@@ -6,7 +6,9 @@ class Cell:
num: int
marked: bool = False
-def bingo(board):
+Board = list[list[Cell]]
+
+def bingo(board: Board) -> bool:
for row in board:
if all(cell.marked for cell in row):
return True
@@ -15,10 +17,13 @@ def bingo(board):
return True
return False
-def solve(nums, boards):
- won = set()
- wins = []
+def solve(nums: list[int], boards: list[Board]) -> tuple[int, int]:
+ won: set[int] = set()
+ wins: list[int] = []
+ num: int
for num in nums:
+ i: int
+ board: Board
for i, board in enumerate(boards):
total = 0
for row in board:
@@ -32,6 +37,8 @@ def solve(nums, boards):
wins.append(num * total)
return wins[0], wins[-1]
+nums: str | list[int]
+boards: list[str] | list[Board]
nums, *boards = open_day(4).read().rstrip().split('\n\n')
nums = list(map(int, nums.split(',')))
boards = [[[Cell(int(n)) for n in l.split()] for l in b.split('\n')] for b in boards]