Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Open Labyrinth solution in Clear category for Open Labyrinth by mz97
end = False
route = ""
def used(p,k):
for i in range(len(p)):
if p[i][0]==k[0] and p[i][1]==k[1]:
return True
return False
def go_again(p,ro,pth):
a=pth[0]
b=pth[1]
c=pth[2]
global route
if ([a-1,b,c-1] in p)==True: #up
ro.append([a-1,b,c-1])
route+="N"
elif ([a+1,b,c-1] in p)==True: #down
ro.append([a+1,b,c-1])
route+="S"
elif ([a,b-1,c-1] in p)==True: #left
ro.append([a,b-1,c-1])
route+="W"
elif ([a,b+1,c-1] in p)==True: #right
ro.append([a,b+1,c-1])
route+="E"
def exit(t,p):
global end
end = True
r=[p[len(p)-1]]
i=0
while r[i]!=[10,10,0]:
go_again(p,r,r[i])
i+=1
def go(t,p,pth):
x=pth[0]
y=pth[1]
z=pth[2]
if t[x-1][y]!=1 and used(p,[x-1,y])==False: #up
p.append([x-1,y,z+1])
if t[x-1][y] == 's':
return exit(t,p)
if t[x+1][y]!=1 and used(p,[x+1,y])==False: #down
p.append([x+1,y,z+1])
if t[x+1][y] == 's':
return exit(t,p)
if t[x][y-1]!=1 and used(p,[x,y-1])==False: #left
p.append([x,y-1,z+1])
if t[x][y-1] == 's':
return exit(t,p)
if t[x][y+1]!=1 and used(p,[x,y+1])==False: #right
p.append([x,y+1,z+1])
if t[x][y+1] == 's':
return exit(t,p)
def checkio(tab):
global route
route = ""
global end
end = False
tab[1][1]='s' #start
path = [[10,10,0]] #starting from exit
i=0
while end==False:
go(tab,path,path[i])
i+=1
return route
Oct. 22, 2016