The optimal matrix (for the rather narrow scope of this challenge) is obtained by "zipping" the elements from the corresponding rows and columns of a square matrix and getting the maximum of each pair.
For instance, given the following matrix:
4 5 6 1 7 2 7 3 0 You can combine it with its transpose to get: [[[4,5,6],[4,1,7]],[[1,7,2],[5,7,3]],[[7,3,0],[6,2,0]]]. If you zip each pair of lists, you obtain the following: [[(4,4),(5,1),(6,7)],[(1,5),(7,7),(2,3)],[(7,6),(3,2),(0,0)]]. The last step is to get the maximum of each pair to get the optimal matrix:
4 5 7 5 7 3 7 3 0 Your task is to output the optimal matrix of a square matrix given as input. The matrix will only contain integers. I/O can be done in any reasonable format. The shortest code in bytes (either in UTF-8 or in the language's custom encoding) wins!
Tests
[[172,29],[29,0]] -> [[172,29],[29,0]] [[4,5,6],[1,7,2],[7,3,0]] -> [[4,5,7],[5,7,3],[7,3,0]] [[1,2,3],[1,2,3],[1,2,3]] -> [[1,2,3],[2,2,3],[3,3,3]] [[4,5,-6],[0,8,-12],[-2,2,4]] -> [[4,5,-2],[5,8,2],[-2,2,4]]
[1,2,3,4]instead of[[1,2],[3,4]]? Would save ~33% \$\endgroup\$