Created
June 27, 2016 08:02
-
-
Save charles2588/aed3155cbbef92071442a5b0a012b75a to your computer and use it in GitHub Desktop.
https://repl.it/C6U5/3 created by charles2588
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
def printsprial(m,n): | |
arr=[] | |
count=0 | |
for i in range(m): | |
arr.append([]) | |
for j in range(n): | |
count+=1 | |
arr[i].append(count) | |
print(arr) | |
topwall=0 | |
rightwall=n-1 | |
leftwall=0 | |
bottomwall=m-1 | |
count=0 | |
i=1 | |
while count<m*n: | |
if i==1: | |
j=leftwall | |
while j<=rightwall: | |
print(arr[topwall][j]) | |
count+=1 | |
j+=1 | |
topwall+=1 | |
i=2 | |
if i==2: | |
j=topwall | |
while j<=bottomwall: | |
print(arr[j][rightwall]) | |
count+=1 | |
j+=1 | |
rightwall-=1 | |
i=3 | |
if i==3: | |
j=rightwall | |
while j>=leftwall: | |
print(arr[bottomwall][j]) | |
count+=1 | |
j-=1 | |
bottomwall-=1 | |
i=4 | |
if i==4: | |
j=bottomwall | |
while j>=topwall: | |
print(arr[j][leftwall]) | |
count+=1 | |
j-=1 | |
leftwall+=1 | |
i=1 | |
printsprial(4,5) | |
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
Python 3.5.1 (default, Dec 2015, 13:05:11) | |
[GCC 4.8.2] on linux | |
>>> [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]] | |
1 | |
2 | |
3 | |
4 | |
5 | |
10 | |
15 | |
20 | |
19 | |
18 | |
17 | |
16 | |
11 | |
6 | |
7 | |
8 | |
9 | |
14 | |
13 | |
12 | |
=> None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment