Given the diagonals of a matrix, reconstruct the original matrix.
The diagonals parallel to the major diagonal (the main diagonals) will be given.
Diagonals: [[5], [4, 10], [3, 9, 15], [2, 8, 14, 20], [1, 7, 13, 19, 25], [6, 12, 18, 24], [11, 17, 23], [16, 22], [21]]
Rules
- The matrix will be non-empty and will consist of positive integers
- You get to choose how the input diagonals will be given:
- starting with the main diagonal and then alternating between the outer diagonals (moving outwards from the main diagonal)
- from the top-right diagonal to the bottom-left diagonal
- from the bottom-left diagonal to the top-right diagonal
- The end matrix will always be a square
- The order of the numbers in the diagonals should be from top-left to bottom-right
- Input and output matrix can be flattened
- This is code-golf, so the shortest answer wins
Test cases
[In]: [[5]]
[Out]: [[5]]
[In]: [[1, 69], [0], [13]]
[Out]: [[1, 0], [13, 69]]
[In]: [[25], [0, 1], [6, 23, 10], [420, 9], [67]]
[Out]: [[6, 0, 25], [420, 23, 1], [67, 9, 10]]