60 lines
1.5 KiB
Python
60 lines
1.5 KiB
Python
|
import sys
|
||
|
|
||
|
I = sys.stdin.read().splitlines()
|
||
|
G = [list(l) for l in I]
|
||
|
W = len(G[0])
|
||
|
H = len(G)
|
||
|
|
||
|
def north():
|
||
|
for x in range(W):
|
||
|
for y in range(H):
|
||
|
if G[y][x] == "O":
|
||
|
for j in range(y-1,0-1,-1):
|
||
|
if G[j][x] == '.':
|
||
|
G[j][x] = "O"
|
||
|
G[j+1][x] = "."
|
||
|
else:
|
||
|
break
|
||
|
|
||
|
def south():
|
||
|
for x in range(W):
|
||
|
for y in range(H-1,0-1,-1):
|
||
|
if G[y][x] == "O":
|
||
|
for j in range(y+1,W,1):
|
||
|
if G[j][x] == '.':
|
||
|
G[j][x] = "O"
|
||
|
G[j-1][x] = "."
|
||
|
else:
|
||
|
break
|
||
|
|
||
|
def east():
|
||
|
for y in range(H):
|
||
|
for x in range(W-1,0-1,-1):
|
||
|
if G[y][x] == "O":
|
||
|
for i in range(x+1,H,1):
|
||
|
if G[y][i] == '.':
|
||
|
G[y][i] = "O"
|
||
|
G[y][i-1] = "."
|
||
|
else:
|
||
|
break
|
||
|
|
||
|
|
||
|
def west():
|
||
|
for y in range(H):
|
||
|
for x in range(W):
|
||
|
if G[y][x] == "O":
|
||
|
for i in range(x-1,0-1,-1):
|
||
|
if G[y][i] == '.':
|
||
|
G[y][i] = "O"
|
||
|
G[y][i+1] = "."
|
||
|
else:
|
||
|
break
|
||
|
|
||
|
for _ in range(1_000):
|
||
|
north()
|
||
|
west()
|
||
|
south()
|
||
|
east()
|
||
|
|
||
|
print(sum((H-y)*row.count('O') for y,row in enumerate(G)))
|