-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday4-2.py
54 lines (40 loc) · 1.25 KB
/
day4-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
import sys
import numpy as np
def main():
file = open('input4.txt', 'r')
input = file.readline().strip().split(',')
boards = []
temp = []
file.readline()
for line in file:
if line == '\n':
boards.append(temp)
temp = []
else:
temp.append(line.split())
boards.append(temp)
lastbingoboard = []
lastinput = []
for i, _ in enumerate(input):
for board in boards:
columns = np.array(board).T.tolist() + board
for row in columns:
if all(a in input[:i+1] for a in row):
lastbingoboard= board
lastinput = input[:i+1]
boards.remove(board)
break
print(lastinput)
print(lastbingoboard)
calculateScore(lastbingoboard, lastinput, 2)
def calculateScore(board, subinput, part):
flatboard = [j for sub in board for j in sub]
for element in subinput:
if element in flatboard:
flatboard.remove(element)
summed = sum(list(map(int, flatboard)))
lastCalled = int(subinput[len(subinput)-1])
score = summed * lastCalled
print("Part " + str(part) + ": " + str(score))
if __name__ == "__main__":
main()