Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1. def dedans(l,i,j,p,q,x):
  2.     for k in range(i,p+1):
  3.         for z in range (q,j+1):
  4.             if x== l[k][z]:
  5.                 return True
  6.     return False
  7.  
  8. def intervalle(liginf,ligsup,colinf,colsup,n):
  9.     return 0 <= liginf <= ligsup < n and 0 <= colinf <= colsup < n
  10.  
  11. def propriete_invariant(l,liginf,colsup,ligsup,colinf,x,n):
  12.     return intervalle(liginf,ligsup,colinf,colsup,n) and dedans(l,liginf,colsup,ligsup,colinf,x)
  13.  
  14. def rechercher(matrice,element) :
  15.     liginf = 0
  16.     colsup = len(matrice[0])-1
  17.     ligsup = len(matrice)-1
  18.     colinf = 0
  19.     assert propriete_invariant(matrice,liginf,colsup,ligsup,colinf,element,len(matrice)), 'erreur init'
  20.     while matrice[liginf][colsup] != element :
  21.         assert colsup-liginf+ligsup-colinf>0, 'variant'
  22.         t = colsup-liginf+ligsup-colinf
  23.         if colsup == 0:
  24.             colsup = len(matrice[0])-1
  25.             liginf += 1
  26.         else:
  27.             colsup -= 1
  28.         assert t> colsup-liginf+ligsup-colinf, 'erreur terminaison'
  29.         assert propriete_invariant(matrice,liginf,colsup,ligsup,colinf,element,len(matrice)), 'erreur iter'
  30.     assert propriete_invariant(matrice,liginf,colsup,ligsup,colinf,element,len(matrice)) and matrice[liginf][colsup]==element, 'erreur obj'
  31.     return(liginf,colsup)
  32.  
  33. matrice = eval(input())
  34. element = int(input())
  35. print(rechercher(matrice,element))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement