Created
September 8, 2019 03:07
-
-
Save atul-chaudhary/c2836a327a124de7cb24c1f99121ee0e to your computer and use it in GitHub Desktop.
Print matrix in spiral
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [[1, 2, 3, 4, 5, 6], | |
[7, 8, 9, 10, 11, 12], | |
[13, 14, 15, 16, 17, 18]] | |
int_row = 0 | |
last_row = 3 | |
int_col = 0 | |
last_col = 6 | |
while(int_row<=last_row and int_col<=last_col): | |
for i in range(int_col,last_col): | |
print(a[int_row][i],end=' ') | |
int_row+=1 | |
for j in range(int_row,last_row): | |
print(a[j][last_col-1],end=' ') | |
last_col-=1 | |
if(int_row<=last_row): | |
for i in range(last_col-1,-1,-1): | |
print(a[last_row-1][i],end=' ') | |
last_row-=1 | |
if(int_col<=last_col): | |
for j in range(last_row-1,0,-1): | |
print(a[j][int_col],end=' ') | |
int_col+=1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment