Magic square by recursive

n=input()
b=map(list,["0"*n]*n)
c=n/2
r=v=0
exec'v+=1;b[r][c]="%3i"%v;z=v%n>0;r+=1+z;r%=n;c+=z;c%=n;'*n*n
for r in b:print" ".join(r)

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page