-
Notifications
You must be signed in to change notification settings - Fork 0
/
part_1.py
63 lines (50 loc) · 1.74 KB
/
part_1.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
61
62
63
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from utils.input_reader import *
def calc_final_score(bingo_input):
numbers_played = bingo_input[0].split(',')
boards = get_boards(bingo_input[2:])
unplayed_sum = 0
board_num = None
for num in numbers_played:
board_num = check_boards(boards, num)
if board_num is not None:
break
for r in range(5):
for c in range(5):
if boards[board_num][r][c] != '*':
unplayed_sum += int(boards[board_num][r][c])
return unplayed_sum * int(num)
def check_boards(boards, number):
for b in range(len(boards)):
for i in range(5):
horizontal_counter = 0
vertical_counter = 0
for j in range(5):
if boards[b][i][j] == number:
boards[b][i][j] = '*'
if boards[b][j][i] == '*':
vertical_counter += 1
if boards[b][i][j] == '*':
horizontal_counter += 1
if horizontal_counter == 5 or vertical_counter == 5:
return b
return None
def get_boards(boards_input):
board_list = []
board = []
for line in boards_input:
if len(line) == 0 and len(board) > 0:
board_list.append(list(board))
board = []
else:
board.append(line.split())
board_list.append(list(board))
return board_list
def main():
file_path = os.path.dirname(__file__) + '/input.txt'
values = get_input_array(filename=file_path)
life_support_rating = calc_final_score(values)
print("Final score in winner board: {}".format(life_support_rating))
main()