Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- matriz=[[0,4,0,0,5],[1,0,5,0,0],[0,-9,8,0,1],[1,0,1,0,-3],[0,4,0,0,0]]
- nume=[]
- m,a,b=1,0,0
- pos_ = matriz[a][b]
- print("",matriz[0],"\n",matriz[1],"\n",matriz[2],"\n",matriz[3],"\n",matriz[4])
- while len(nume)<len(matriz)*len(matriz[0])-1:
- while m==1: #bajar
- try:
- if matriz[a+1][b]!=555:
- nume.append(pos_)
- matriz[a][b]=555
- a+=1
- pos_= matriz[a][b]
- else:
- m+=1
- except:
- m+=1
- while m==2: #derecha
- try:
- if matriz[a][b+1]!=555:
- nume.append(pos_)
- matriz[a][b]=555
- b+=1
- pos_= matriz[a][b]
- else:
- m+=1
- except:
- m+=1
- while m==3: #subir
- if a>0 and matriz[a-1][b]!=555:
- nume.append(pos_)
- matriz[a][b]=555
- a-=1
- pos_= matriz[a][b]
- else:
- m+=1
- while m==4: #izquierda
- if b>0 and matriz[a][b-1]!=555:
- nume.append(pos_)
- matriz[a][b]=555
- b-=1
- pos_= matriz[a][b]
- else:
- m+=1
- if m==5:
- m=1
- nume.append(pos_)
- print(nume)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement