Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def dedans(l,i,j,p,q,x):
- for k in range(i,p+1):
- for z in range (q,j+1):
- if x== l[k][z]:
- return True
- return False
- def intervalle(liginf,ligsup,colinf,colsup,n):
- return 0 <= liginf <= ligsup < n and 0 <= colinf <= colsup < n
- def propriete_invariant(l,liginf,colsup,ligsup,colinf,x,n):
- return intervalle(liginf,ligsup,colinf,colsup,n) and dedans(l,liginf,colsup,ligsup,colinf,x)
- def rechercher(matrice,element) :
- liginf = 0
- colsup = len(matrice[0])-1
- ligsup = len(matrice)-1
- colinf = 0
- assert propriete_invariant(matrice,liginf,colsup,ligsup,colinf,element,len(matrice)), 'erreur init'
- while matrice[liginf][colsup] != element :
- assert colsup-liginf+ligsup-colinf>0, 'variant'
- t = colsup-liginf+ligsup-colinf
- if colsup == 0:
- colsup = len(matrice[0])-1
- liginf += 1
- else:
- colsup -= 1
- assert t> colsup-liginf+ligsup-colinf, 'erreur terminaison'
- assert propriete_invariant(matrice,liginf,colsup,ligsup,colinf,element,len(matrice)), 'erreur iter'
- assert propriete_invariant(matrice,liginf,colsup,ligsup,colinf,element,len(matrice)) and matrice[liginf][colsup]==element, 'erreur obj'
- return(liginf,colsup)
- matrice = eval(input())
- element = int(input())
- print(rechercher(matrice,element))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement