-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpart1.py
34 lines (27 loc) · 886 Bytes
/
part1.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
with open("input.txt") as file:
sequence = list(map(int, file.readline().split(',')))
boards = [[]]
for line in filter(lambda line: line.strip(), file):
line = list(map(int, line.split()))
if len(boards[-1]) == 5:
boards.append([line])
else:
boards[-1].append(line)
winner_board = None
for number in sequence:
for board in boards:
for line in board:
for i in range(5):
if line[i] == number:
line[i] = None
for i in range(5):
if all(board[i][j] is None for j in range(5)) or \
all(board[j][i] is None for j in range(5)):
winner_board = board
if winner_board:
break
board_sum = sum(
sum(filter(lambda item: item is not None, line))
for line in winner_board
)
print(board_sum * number)