You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.2 KiB

lines = open("input.txt", 'r').read().splitlines()
draw = [int(i) for i in lines[0].split(",")]
boards = []
for s in range(2, len(lines),6):
boards.append([[int(j) for j in lines[i].split()] for i in range(s,s+5)])
winsOn = [-1] * len(boards)
# i should really make an attempt to optimize this
for b in range(0, len(boards)):
for i in range(0, 5):
latest = 0
for j in range(0, 5):
if boards[b][i][j] not in draw:
break
drawIndex = draw.index(boards[b][i][j])
if drawIndex > latest:
latest = drawIndex
if winsOn[b] == -1 or winsOn[b] > latest:
winsOn[b] = latest
latest = 0
for j in range(0, 5):
if boards[b][j][i] not in draw:
break
drawIndex = draw.index(boards[b][j][i])
if drawIndex > latest:
latest = drawIndex
if winsOn[b] > latest :
winsOn[b] = latest
summa = 0
summaLose = 0
winBoard = winsOn.index(min(winsOn))
loseBoard = winsOn.index(max(winsOn))
for row in boards[winBoard]:
for n in row:
if n not in draw[:winsOn[winBoard]+1]:
summa += n
for row in boards[loseBoard]:
for n in row:
if n not in draw[:winsOn[loseBoard]+1]:
summaLose += n
print(draw[winsOn[winBoard]]*summa)
print(draw[winsOn[loseBoard]]*summaLose)