0
I have the following problem:
I have a large matrix [10x10 for example] It has values from 1 to 9.
I must check whether a vector [1, 2, 3, 4, 5] (for example) is contained in this matrix. When finding the first number of the vector within the matrix, I must check the neighbors. But, if number one is in the middle of the matrix, I have to check the surroundings of 8 numbers. How do I do this reading? Please, if someone can explain me, try to do it in the most "silly" way possible, using while?
The functions below are not complete:
def ProcuraPrimeiroNumero(retang, padrao, i, j):
'''Esta função procura o primeiro numero na matriz'''
while i<num_lin: #procurando o 1º numero a partir da primeira linha
while j<num_col: #procurando o 1º numero a partir da primeira coluna
if retang[i][j] == padrao[0]: #Se o primeiro numero do vetor for igual ao primeiro numero da matriz
VerificaSeCabe (retang, t, direçao, i, j)
if VerificaSeCabe == 1:
def VerificaSeCabe(retang, direçao, t, i, j):
k = 1
l = 1
aux_mat =[]
x = 0
y = 0
while x<num_lin:
lin = []
y = 0
while y<num_col:
lin=lin+[0]
y=y+1
aux_mat = aux_mat +[lin]
x=x+1
while k<=4: #contador para as direções
while l<=4: #contador para as direções
if ((x+t-1)<=i-x):
if (y+t-1<=j-1):
cabe = 1
else:
cabe = -1
How you are representing this matrix in Python?
– Woss
This is a college job. I read the matrix of a txt file. After reading, I count the number of rows and columns. But the "thick" of the algorithm is in that part of "scanning" around a coordinate
– Daniel M M
You can [Edit] the question and add the code you already have?
– Woss
I’ll try to do that.
– Daniel M M
Can you better define what would be "contained in the matrix"? You should only search in the rows of the matrix or is it worth being in the columns and diagonals?
– Woss
That. I must "check" all rows, columns and diagonals. As if to check clockwise: up, diagonal, right, diagonal, low, diagonal, left, diagonal (managed to understand?)
– Daniel M M
However, my problem is that I’m only able to check the points above, diagonal, right, diagonal and below. The "left" side I’m having trouble checking
– Daniel M M