Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adiciona condicoes nos casos existentes, para considerar as direcoes #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions 24-doctest/matrizespiral.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ def entrada(self, linha, coluna):
[[1], [2]]
>>> me.entrada(3, 3)
[[1, 2, 3], [8, 9, 4], [7, 6, 5]]
>>> me.entrada(3, 4)
[[1, 2, 3, 4], [10, 11, 12, 5], [9, 8, 7, 6]]
>>> me.entrada(4, 3)
[[1, 2, 3], [10, 11, 4], [9, 12, 5], [8, 7, 6]]
>>> me.entrada(6, 5)
[[1, 2, 3, 4, 5], [18, 19, 20, 21, 6], [17, 28, 29, 22, 7], [16, 27, 30, 23, 8], [15, 26, 25, 24, 9], [14, 13, 12, 11, 10]]
"""
matriz = [[ 0 for x in range(coluna) ] for y in range (linha)]
i = 0
Expand All @@ -29,10 +35,10 @@ def entrada(self, linha, coluna):
matriz[i][j] = n + 1

muda_direcao = (
j == coluna -1 or
i == linha -1 or
(j == 0 and i != 0) or
matriz[i + incremento_linha][j + incremento_coluna] != 0
(j == coluna -1 and direcao == 1) or
(i == linha -1 and direcao == 2) or
(j == 0 and direcao == 3) or
(n > 1 and matriz[i + incremento_linha][j + incremento_coluna] != 0)
)

if muda_direcao:
Expand All @@ -53,6 +59,9 @@ def entrada(self, linha, coluna):
incremento_linha = -1
incremento_coluna = 0

i+=incremento_linha
j+=incremento_coluna

return matriz

if __name__ == "__main__":
Expand Down