aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--2021/04/puzzles.py13
1 files changed, 6 insertions, 7 deletions
diff --git a/2021/04/puzzles.py b/2021/04/puzzles.py
index 581aef5..858450f 100644
--- a/2021/04/puzzles.py
+++ b/2021/04/puzzles.py
@@ -24,12 +24,11 @@ def bingo(board: board) -> bool:
def main() -> None:
boards: list[board] = []
with open("input", "r", encoding="utf-8") as f:
+ draws = list(map(int, f.readline().split(",")))
lines = f.readlines()
for i, line in enumerate(lines):
- if i == 0:
- draws = list(map(int, line.strip().split(",")))
- elif line == "\n":
- boards.append([list(map(int, lines[i + j].strip().split())) for j in range(1, 6)])
+ if line == "\n":
+ boards.append([list(map(int, lines[i + j].split())) for j in range(1, 6)])
# START PART 1
while not any(bingo(b) for b in boards):
@@ -37,9 +36,9 @@ def main() -> None:
while len(draws) > 0 and len(boards) > 0:
# END PART 2
num = draws.pop(0)
- for i, board in enumerate(boards):
- for j, row in enumerate(board):
- boards[i][j] = [-1 if n == num else n for n in row]
+ for board in boards:
+ for i, row in enumerate(board):
+ board[i] = [-1 if n == num else n for n in row]
# START PART 2
boards = list(filter(lambda b: not bingo(b), boards))
# END PART 2