-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution4-2.py
More file actions
94 lines (69 loc) · 1.91 KB
/
solution4-2.py
File metadata and controls
94 lines (69 loc) · 1.91 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import sys
winConditions = {
1: [1,2,3,4,5],
2: [6,7,8,9,10],
3: [11,12,13,14,15],
4: [16,17,18,19,20],
5: [21,22,23,24,25],
6: [1,6,11,16,21],
7: [2,7,12,17,22],
8: [3,8,13,18,23],
9: [4,9,14,19,24],
10: [5,10,15,20,25]
}
# add the values up. if it's -5, it's a win
def isWin(board):
linesums = set()
for line in winConditions.values():
ls = 0
for x in line:
ls += board[x]
linesums.add(ls)
if -5 in linesums:
return True
return False
def main():
recordTurns = -1
recordScore = 0
file = open('input4.txt', 'r')
bingoInput = file.readline()
line = file.readline()
bingoInput = bingoInput.split(',')
line = file.readline()
while line:
board = {}
idxboard = {}
boardsum = 0
idx = 1
# load board in dict
# load values into a indexer
for x in range(0,5):
line = line.split(' ')
for num in line:
if num == '':
continue
value = int(num)
board[idx] = value
idxboard[value] = idx
boardsum += value
idx+=1
line = file.readline()
# play board
for i in range(0, len(bingoInput)):
currentValue = int(bingoInput[i])
if currentValue not in idxboard:
continue
boardsum -= currentValue
boardIndex = idxboard[currentValue]
board[boardIndex] = -1
test = isWin(board)
# if it wins
if isWin(board):
if i > recordTurns:
recordTurns = i
recordScore = currentValue * boardsum
break
line = file.readline()
# print(recordTurns)
# print(recordScore)
main()