-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04.py
41 lines (33 loc) · 1.25 KB
/
04.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from modules import DataManager
data = DataManager(__file__).get_data_string()
def bingo_score(draw_order, input):
# Convert draw order and boards to integers
draw_order = list(map(int, draw_order.split(",")))
boards = []
for row in input:
if not row:
boards.append([])
else:
boards[-1].append(list(map(int, row.split())))
for num in draw_order:
for board in boards:
# Mark the number on the board
for i in range(5):
for j in range(5):
if board[i][j] == num:
board[i][j] = -1 # Use -1 to mark the number
# Check if the board has a winning row or column
for i in range(5):
if all(board[i][j] == -1 for j in range(5)) or all(
board[j][i] == -1 for j in range(5)
):
# Calculate the score of the winning board
score = sum(
board[i][j]
for i in range(5)
for j in range(5)
if board[i][j] != -1
)
return score * num
return None
print(bingo_score(data[0], data[1:]))