Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Stepping Stones Puzzle by mildm
def stepping_stones(n: int, ones: list[tuple[int, int]]) -> int:
def move(ll,x,y,v):
l=ll[:]
l[x+y*n]=-1
for i in range(max(x-1,0),min(x+2,n)):
for j in range(max(y-1,0),min(y+2,n)):
l[i+j*n]+=0 if l[i+j*n]<0 else v
return l
l=[0]*(n*n)
for x,y in ones:
l=move(l,x,y,1)
def bst(l,i):
p=0
mx=i-1
while i in l[p:]:
p=l.index(i,p)
x,y,p=p%n,p//n,p+1
mx=max(mx,bst(move(l,x,y,i),i+1))
return mx
return bst(l,2)
Aug. 30, 2023