diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2021-12-04 06:50:52 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2021-12-04 06:50:52 +0000 |
commit | e3c33a5247332f083af8a84a0c3e6fc6650e8845 (patch) | |
tree | 0d300fab24807b0eab3d75c51d7172f9ec0c3b8a | |
parent | 1ec51c971ba7eff1e07cb01b0eaedd89ac138f1c (diff) | |
download | aoc2021-e3c33a5247332f083af8a84a0c3e6fc6650e8845.tar.gz aoc2021-e3c33a5247332f083af8a84a0c3e6fc6650e8845.tar.xz aoc2021-e3c33a5247332f083af8a84a0c3e6fc6650e8845.zip |
day 4: type annotations
-rw-r--r-- | 4.py | 15 |
1 files changed, 11 insertions, 4 deletions
@@ -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] |