JavaScript (ES6), 65 bytes
Expects the diagonals from top-right to bottom-left.
a=>a[w=a.length>>1].map((_,y,A)=>A.map((_,x)=>a[w+y-x][x<y?x:y]))
Also 65 bytes:
a=>[...a[w=a.length>>1]].map((_,y,A)=>A.map(_=>a[w+y--].shift()))
Flatten format, 89 bytes
Or 89 bytes with this silly attempt at usingThis version expects a flatten formatarray of the diagonals from top-right to bottom-left and returns another flatten array.
The only benefit is that there's only one map(). But the math is much more verbose. So yeah ... that's a bit silly. :-) There may be a better/shorter formula, though.
a=>a.map((_,x)=>a[y=x/w|0,x%=w,n=y+w+~x,(q=n>w&&n-w)*~q-n*~n/2+(x<y?x:y)],w=a.length**.5)
Given an input array of length \$N\$, we define for each index \0ドル\le i \lt N\$:
$$x=i\bmod w\\ y=\lfloor i/w \rfloor\\ n=y+w-x-1\\ q=\max(n-w,0)$$
where \$w\$ is the width of the matrix, i.e. \$\sqrt{N}\$.
The output value at this position is the value stored in the input array at the following index:
$$\frac{n\times(n+1)}{2}-q\times(q+1)+\min(x,y)$$
JavaScript (ES6), 65 bytes
Expects the diagonals from top-right to bottom-left.
a=>a[w=a.length>>1].map((_,y,A)=>A.map((_,x)=>a[w+y-x][x<y?x:y]))
Also 65 bytes:
a=>[...a[w=a.length>>1]].map((_,y,A)=>A.map(_=>a[w+y--].shift()))
Or 89 bytes with this silly attempt at using a flatten format:
a=>a.map((_,x)=>a[y=x/w|0,x%=w,n=y+w+~x,(q=n>w&&n-w)*~q-n*~n/2+(x<y?x:y)],w=a.length**.5)
JavaScript (ES6), 65 bytes
Expects the diagonals from top-right to bottom-left.
a=>a[w=a.length>>1].map((_,y,A)=>A.map((_,x)=>a[w+y-x][x<y?x:y]))
Also 65 bytes:
a=>[...a[w=a.length>>1]].map((_,y,A)=>A.map(_=>a[w+y--].shift()))
Flatten format, 89 bytes
This version expects a flatten array of the diagonals from top-right to bottom-left and returns another flatten array.
The only benefit is that there's only one map(). But the math is much more verbose. So yeah ... that's a bit silly. :-) There may be a better/shorter formula, though.
a=>a.map((_,x)=>a[y=x/w|0,x%=w,n=y+w+~x,(q=n>w&&n-w)*~q-n*~n/2+(x<y?x:y)],w=a.length**.5)
Given an input array of length \$N\$, we define for each index \0ドル\le i \lt N\$:
$$x=i\bmod w\\ y=\lfloor i/w \rfloor\\ n=y+w-x-1\\ q=\max(n-w,0)$$
where \$w\$ is the width of the matrix, i.e. \$\sqrt{N}\$.
The output value at this position is the value stored in the input array at the following index:
$$\frac{n\times(n+1)}{2}-q\times(q+1)+\min(x,y)$$
JavaScript (ES6), 65 bytes
Expects the diagonals from top-right to bottom-left.
a=>a[w=a.length>>1].map((_,y,A)=>A.map((_,x)=>a[w+y-x][x<y?x:y]))
Also 65 bytes:
a=>[...a[w=a.length>>1]].map((_,y,A)=>A.map(_=>a[w+y--].shift()))
Or 89 bytes with this silly attempt at using a flatten format:
a=>a.map((_,x)=>a[y=x/w|0,x%=w,n=y+w+~x,(q=n>w&&n-w)*~q-n*~n/2+(x<y?x:y)],w=a.length**.5)
JavaScript (ES6), 65 bytes
Expects the diagonals from top-right to bottom-left.
a=>a[w=a.length>>1].map((_,y,A)=>A.map((_,x)=>a[w+y-x][x<y?x:y]))
Also 65 bytes:
a=>[...a[w=a.length>>1]].map((_,y,A)=>A.map(_=>a[w+y--].shift()))
JavaScript (ES6), 65 bytes
Expects the diagonals from top-right to bottom-left.
a=>a[w=a.length>>1].map((_,y,A)=>A.map((_,x)=>a[w+y-x][x<y?x:y]))
Also 65 bytes:
a=>[...a[w=a.length>>1]].map((_,y,A)=>A.map(_=>a[w+y--].shift()))
Or 89 bytes with this silly attempt at using a flatten format:
a=>a.map((_,x)=>a[y=x/w|0,x%=w,n=y+w+~x,(q=n>w&&n-w)*~q-n*~n/2+(x<y?x:y)],w=a.length**.5)
JavaScript (ES6), 65 bytes
Expects the diagonals from top-right to bottom-left.
a=>a[w=a.length>>1].map((_,y,A)=>A.map((_,x)=>a[w+y-x][x<y?x:y]))
Also 65 bytes:
a=>[...a[w=a.length>>1]].map((_,y,A)=>A.map(_=>a[w+y--].shift()))
JavaScript (ES6), 65 bytes
Expects the diagonals from top-right to bottom-left.
a=>a[w=a.length>>1].map((_,y,A)=>A.map((_,x)=>a[w+y-x][x<y?x:y]))
JavaScript (ES6), 65 bytes
Expects the diagonals from top-right to bottom-left.
a=>a[w=a.length>>1].map((_,y,A)=>A.map((_,x)=>a[w+y-x][x<y?x:y]))
Also 65 bytes:
a=>[...a[w=a.length>>1]].map((_,y,A)=>A.map(_=>a[w+y--].shift()))