caird coinheringaahing ♦
- 50.9k
- 11
- 133
- 364
Jelly, 24(削除) 24 (削除ここまで) 19 bytes
ŒD,Œd§Ḣ€,U$j€SW€j§U$+Æṭj€SW€j§,"`j"Ɗ
ŒD,Œd§Ḣ€,U$j€SW€j§U$+Æṭj€SW€j§,"`j"Ɗ - Main link. Takes a matrix MA on the right
ŒD $ - Collect the previous two links:
U - Yield the diagonalsReverse each row of MA
Œd rev(A) = A with reversed rows
, - Yield the antidiagonalspair of[A, Mrev(A)]
, + - Do this again -on Pair[A, themrev(a)]:
€ [A, rev(A)]U -> For[rev(A), each:A]
§Ḣ [A, rev(A)],U$ -> [[A, rev(A)], [rev(A), A]]
Æṭ - Take the leadingtrace sumof each.
This returns [[Tr(A), Tr(rev(A))],U$ [Tr(rev(A)), Tr(A)]]
- Pair that with its reverse. Call this l
where Tr(·) returns the trace
S - Yield the sums of the columns of MA
€ - Over each pair in l:
j - Insert the column sums between their elements
W€ - Wrap each in an array
Ɗ - Group and run the previous commands on MA:
§ - Yield the row sums of MA
,"` - Pair each with itself
" - Zip the rows of MA with the pairs of row sums
j - Insert each row between each pair.
j - Insert the rows plus their sums in between the diagonal and column sums
Jelly, 24 bytes
ŒD,Œd§Ḣ€,U$j€SW€j§,"`j"Ɗ
ŒD,Œd§Ḣ€,U$j€SW€j§,"`j"Ɗ - Main link. Takes a matrix M on the right
ŒD - Yield the diagonals of M
Œd - Yield the antidiagonals of M
, - Pair them
€ - For each:
§Ḣ - Take the leading sum
,U$ - Pair that with its reverse. Call this l
S - Yield the sums of the columns of M
€ - Over each pair in l:
j - Insert the column sums between their elements
W€ - Wrap each in an array
Ɗ - Group and run the previous commands on M:
§ - Yield the row sums of M
,"` - Pair each with itself
" - Zip the rows of M with the pairs of row sums
j - Insert each row between each pair.
j - Insert the rows plus their sums in between the diagonal and column sums
Jelly, (削除) 24 (削除ここまで) 19 bytes
,U$+Æṭj€SW€j§,"`j"Ɗ
,U$+Æṭj€SW€j§,"`j"Ɗ - Main link. Takes a matrix A on the right
$ - Collect the previous two links:
U - Reverse each row of A
rev(A) = A with reversed rows
, - Yield the pair [A, rev(A)]
+ - Do this again on [A, rev(a)]:
[A, rev(A)]U -> [rev(A), A]
[A, rev(A)],U$ -> [[A, rev(A)], [rev(A), A]]
Æṭ - Take the trace of each.
This returns [[Tr(A), Tr(rev(A))], [Tr(rev(A)), Tr(A)]]
where Tr(·) returns the trace
S - Yield the sums of the columns of A
€ - Over each pair in l:
j - Insert the column sums between their elements
W€ - Wrap each in an array
Ɗ - Group and run the previous commands on A:
§ - Yield the row sums of A
,"` - Pair each with itself
" - Zip the rows of A with the pairs of row sums
j - Insert each row between each pair.
j - Insert the rows plus their sums in between the diagonal and column sums
Jelly, 24 bytes
ŒD,Œd§Ḣ,ドルU$j€SW€j§,"`j"Ɗ
I know there's already 2 Jelly answers, but this, I think, is fairly different from them both, and is shorter.
The Footer in the TIO link converts the inputs into 2D arrays, runs the above link over them then outputs them similar to the input format.
How it works
ŒD,Œd§Ḣ,ドルU$j€SW€j§,"`j"Ɗ - Main link. Takes a matrix M on the right
ŒD - Yield the diagonals of M
Œd - Yield the antidiagonals of M
, - Pair them
€ - For each:
§Ḣ - Take the leading sum
,U$ - Pair that with its reverse. Call this l
S - Yield the sums of the columns of M
€ - Over each pair in l:
j - Insert the column sums between their elements
W€ - Wrap each in an array
Ɗ - Group and run the previous commands on M:
§ - Yield the row sums of M
,"` - Pair each with itself
" - Zip the rows of M with the pairs of row sums
j - Insert each row between each pair.
j - Insert the rows plus their sums in between the diagonal and column sums