PY
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
def solve(n):
m,c,start = [[0]*n for i in range(n)],1,[0,n-1]
while start[1] >= 0:
p = [start[0],start[1]]
while p[0] < n and p[1] < n:
m[p[0]][p[1]] = c
c,p[0],p[1] = c+1,p[0]+1,p[1]+1
start[1] -= 1
start = [1,0]
while start[0] < n:
p = [start[0],start[1]]
while p[0] < n and p[1] < n:
m[p[0]][p[1]] = c
c,p[0],p[1] = c+1,p[0]+1,p[1]+1
start[0] += 1
show(m)
def fill(x,n):
s = str(x)
return s + " "*(n-len(s))
def show(m):
x = 0
for row in m:
c = max(row)
if x < c:
x = c
x = len(str(x))
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run