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.
 
 

39 lines
944 B

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)])
earliestWin = len(draw)
winBoard = 0
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
index = draw.index(boards[b][i][j])
if index > latest:
latest = index
if latest < earliestWin and latest != 0:
earliestWin = latest
winBoard = int(b)
latest = 0
for j in range(0, 5):
if boards[b][j][i] not in draw:
break
index = draw.index(boards[b][j][i])
if index > latest:
latest = index
if latest < earliestWin and latest != 0:
earliestWin = latest
winBoard = b
summa = 0
for row in boards[winBoard]:
for n in row:
if n not in draw[:earliestWin+1]:
summa += n
print(draw[earliestWin]*summa)