parent
1777f5bb24
commit
8fa85c75cd
2 changed files with 52 additions and 0 deletions
@ -0,0 +1,39 @@ |
||||
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) |
Loading…
Reference in new issue