Vyxal, 14 bytes
f=ṖL√vẇ'ÞD?=;h
Math? Sensible methods of putting things into arrays? Programs that finish in reasonable time? Couldn't be me.
Times out for anything bigger than a 2x2 matrix.
Explained
f=ṖL√vẇ'ÞD?=;h
f=ṖL√ # Push all permutations of the flattened input, as well as the square root of the length of the flattened input
vẇ # Split each permutation into chunks of that length
'ÞD?=; # Keep those only where the diagonals equal the input (this basically means try each and every single possible matrix from the input until one is found with the same diagonals)
h # Get the first (and only) item
lyxal ♦
- 35.6k
- 2
- 69
- 148