paste bin

malic
Python
def output(s):
    print(s,end="")

N=int(input())
ORDER=2*N-1
matrix=[ [ 0 for _ in range(ORDER) ] for _ in range(ORDER) ]
i=1
x=0
y=ORDER//2
while i<=ORDER**2:
    matrix[x][y]=i
    nextX=x-1
    if nextX<0:
        nextX = ORDER-1
    nextY=y+1
    if nextY==ORDER:
        nextY = 0
    if matrix[nextX][nextY] != 0:
        nextX=x+1
        if nextX==ORDER:
            nextX=0
        nextY=y
    x=nextX
    y=nextY
    i+=1
for it in matrix:
    firstChar=True
    for num in it:
        if firstChar:
            firstChar=False
        else:
            output(" ")
        output(num)
    print()

2020 C2QB

fork this code