# creating the maze without walls
from numpy import *
m = array([[10,10,10,10,10,10,10,10,10,10],
             [10,6,5,4,3,3,4,5,6,10],
             [10,5,4,3,2,2,3,4,5,10],
             [10,4,3,2,1,1,2,3,4,10],
             [10,3,2,1,0,0,1,2,3,10],
             [10,3,2,1,0,0,1,2,3,10],
             [10,4,3,2,1,1,2,3,4,10],
             [10,5,4,3,2,2,3,4,5,10],
             [10,6,5,4,3,3,4,5,6,10],
             [10,10,10,10,10,10,10,10,10,10]])
w = array([[10,10,10,10,10,10,10,10,10,10],
             [10,6,5,4,3,3,4,5,6,10],
             [10,5,4,3,2,2,3,4,5,10],
             [10,4,3,2,1,1,2,3,4,10],
             [10,3,2,1,0,0,1,2,3,10],
             [10,3,2,1,0,0,1,2,3,10],
             [10,4,3,2,1,1,2,3,4,10],
             [10,5,4,3,2,2,3,4,5,10],
             [10,6,5,4,3,3,4,5,6,10],
             [10,10,10,10,10,10,10,10,10,10]])



#let x and y be present positions
#start position 1,1
x=y=1
while(m[x][y]!=0):
    w[x][y] = 9
    a = m[x][y]     # value of the present position
    d = m[x+1][y]
    u = m[x-1][y]
    l = m[x][y-1]
    r = m[x][y+1]
    t = min(u,d,l,r)
    if (d == t):
        x = x+1
    elif(r == t):
        y =y+1
    elif(u==t):
        x = x-1
    elif( l ==t):
        y = y-1
if(m[x][y]==0):
    w[x][y] = 9
    a = m[x][y]  # value of the present position
    d = m[x + 1][y]
    u = m[x - 1][y]
    l = m[x][y - 1]
    r = m[x][y + 1]
    t = min(u, d, l, r)
    if (d == t):
        x = x + 1
    elif (r == t):
        y = y + 1
    elif (u == t):
        x = x - 1
    elif (l == t):
        y = y - 1

print(w)













