-
Notifications
You must be signed in to change notification settings - Fork 0
/
day_4_part_2.py
60 lines (50 loc) · 1.41 KB
/
day_4_part_2.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from sys import stdin
def check_win(board):
for i in range(5):
row = []
for j in range(5):
row.append(bool(board[i][j] is None))
if all(row) is True:
return True
for i in range(5):
col = []
for j in range(5):
col.append(bool(board[j][i] is None))
if all(col) is True:
return True
return False
def calculate_score(board):
total = 0
for row in board:
total += sum(filter(None, row))
return total
numbers = list(map(int, input().split(",")))
boards = []
counter = 0
board = []
for line in stdin:
if line.strip():
board.append(list(map(int, filter(None, line.strip().split(" ")))))
counter += 1
if counter % 5 == 0:
boards.append(board)
board = []
min_num = 0
score = 0
numu = 0
for board in boards:
counter = 0
for number in numbers:
for i in range(5):
for j in range(5):
if board[i][j] == number:
board[i][j] = None
if check_win(board):
if counter > min_num: # Only line difference from part 1
min_num = counter
score = calculate_score(board)
numu = number
break
else:
counter += 1
print(f"Final Score: {score * numu}")