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.

43 lines
1.1 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)
for b in range(0, len(boards)):
for i in range(0, 5):
latestH = 0
latestV = 0
for j in range(0, 5):
if boards[b][i][j] not in draw or boards[b][j][i] not in draw:
break
drawIndex = draw.index(boards[b][i][j])
if drawIndex > latestH:
latestH = drawIndex
drawIndex = draw.index(boards[b][j][i])
if drawIndex > latestV:
latestV = drawIndex
if winsOn[b] == -1 or winsOn[b] > latestH:
winsOn[b] = latestH
if winsOn[b] == -1 or winsOn[b] > latestV:
winsOn[b] = latestV
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)