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 pattern(N, a=1,b=0):
if N>0:
lst[b]=N
if a<=2:
if a==1: pattern(N-1,2,b+1)
else: pattern(N,a-1,b+1)
def fill(subcount, N=1, row=0, col=0, direction=0, count=0):
arr[row][col]=N
if N<Number*Number:
if subcount==1:
direction=direction+1
count=count+1
subcount=lst[count]
else: subcount=subcount-1
if direction%4==0:
col=col+1
elif direction%4==1:
row=row+1
elif direction%4==2:
col=col-1
else: row=row-1
fill(subcount,N+1,row,col,direction,count)
def Disp(N,a=0):
if N<Number:
print(arr[N][a], end=' '*(1+len(str(arr[Number//2][a]))-len(str(arr[N][a])) ) )#With Spaces as per the biggest numbers which are in the middle row
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run