Skip to content

Instantly share code, notes, and snippets.

@dmattosr
Created May 26, 2015 04:23
Show Gist options
  • Save dmattosr/c5b85d7edafa88a4e538 to your computer and use it in GitHub Desktop.
Save dmattosr/c5b85d7edafa88a4e538 to your computer and use it in GitHub Desktop.
def check(matriz):
def getXY(row, col, matriz):
lCol =[matriz[x][col] for x in range(len(matriz)) if x!=row]
fila = matriz[row]
lFil = [fila[x] for x in range(len(fila)) if x!=col]
return lCol+lFil
l = range(len(matriz))
for row in l:
encontrado = False
for col in l:
if matriz[row][col] in getXY(row,col,matriz):
encontrado = True
exit
if encontrado:
return False
return True
matriz = [
[4,3,2,1],
[2,1,3,4],
[1,2,4,3],
[3,4,1,2],]
print check(matriz) # (True)
matriz = [
[4,3,2,1],
[2,4,3,4],
[1,2,4,3],
[3,4,1,2],]
print check(matriz) # (False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment