Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Territory of Go by pokosasa
from itertools import product
def territory(board):
H,W=len(board),len(board[0])
used=set()
res={"B":0,"W":0}
for i,j in product(range(H),range(W)):
if board[i][j]!="+" or (i,j) in used:
continue
color=None
in_territory=True
group={(i,j)}
stack=[(i,j)]
while stack:
i2,j2=stack.pop()
for di,dj in ((1,0),(0,1),(-1,0),(0,-1)):
ni,nj=i2+di,j2+dj
if not (0<=ni
June 18, 2020
Comments: