-
Notifications
You must be signed in to change notification settings - Fork 0
/
pretty.py
38 lines (38 loc) · 838 Bytes
/
pretty.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
def prettyPrint(A):
n=A+(A-1)
a=[[0]*n for xyz in range(n)]
value=A
dir=0
T=0
B=len(a)-1
L=0
R=len(a)-1
while T<=B and L<=R:
if dir is 0:
for j in range(L,R+1):
a[T][j]=value
T+=1
dir =1
continue
if dir is 1:
for j in range(T,B+1):
a[j][R]=value
R-=1
dir=2
continue
if dir is 2:
for j in range(R,L-1,-1):
a[B][j]=value
dir=3
B-=1
if dir is 3:
for j in range(B,T-1,-1):
a[j][L]=value
dir=0
L+=1
value-=1
for i in range(len(a)):
for j in range(len(a)):
print(a[i][j],end=" ")
print()
prettyPrint(10)