def ShortestDistance(maps,i,j,short,k): #i,j-->current position.
x=0
y=0
for a in range(0, len(maps)):
for b in range(0, len(maps[0])):
if maps[a][b] == 2:
x = a
y = b
if (i==x) and (j==y):
short=min(short,k)
return short
maps[i][j]=3
if within(i+1,j) and possible(maps,i+1,j):
return ShortestDistance(maps,i+1,j,short,k+1)
if within(i, j+1) and possible(maps,i, j+1):
return ShortestDistance(maps,i,j+1,short,k+1)
if within(i-1,j) and possible(maps,i-1,j):
return ShortestDistance(maps,i-1,j,short,k+1)
if within(i,j-1) and possible(maps,i,j-1):
return ShortestDistance(maps,i,j-1,short,k+1)
maps[i][j]=0
result=ShortestDistance(maps,0,0,longest,0)
if result is None:
answer=-1
else:
answer=result
What I'm trying to do here is to have the function go through all the if statements in the function whether the previous if statement was true or not. For instance, I want my 3rd if statement in my code to go through as well even if the 2nd one was true (in this case, it seems like the computer isn't going through the 3rd one). My ultimate goal is to find the minimum value of k for ALL THE POSSIBLE CASES. How would I be able to make it possible?
Aucun commentaire:
Enregistrer un commentaire