Number Spiral: Edges

12910254381124567122316151413221718192021

Let f(y,x) represent the number in row y and column x.

Top Edge

f(1,x)={x2 if x is odd,(x1)2+1 if x is even.

Left Edge

f(y,1)={y2 if y is even,(y1)2+1 if y is odd.

Places Relative to Diagonal

(y,x) falls exactly on the diagonal if and only if y=x.

(y,x) falls above/on the right of diagonal if and only if y<x.

(y,x) falls below/on the left of the diagonal if and only if y>x.

Formulas

f(y,x)={f(1,x)(y1) if yx and x is odd,f(1,x)+(y1) if yx and x is even,f(y,1)+(x1) if yx and x is odd,f(y,1)(x1) if yx and x is even.