Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

deleted 31 characters in body
Source Link
flawr
  • 44.1k
  • 7
  • 109
  • 253

MATL, 13(削除) 13 (削除ここまで) 11 bytes

This uses logical indexing. As an index we use an identity matrix of the size of the input and or it with it's flipped version, just like in my Octave answer. Thanks @LuisMendo for -2 bytes:)

GG&nxXytPY|tZyXytPY|)s

Explanation

GG t push input twice to stack
 &n Zy get size of matrix
 x  discard one of the two size numbers
 Xy get an identity matrix of that size
 t duplicate the identity matrix
 P flip one of the identty matrices
 Y| logical OR the two identity matrices
 ) perform (logical) indexing to the original matrix
 s compute the sum

Try it online! Try it online!

MATL, 13 bytes

This uses logical indexing. As an index we use an identity matrix of the size of the input and or it with it's flipped version, just like in my Octave answer.

GG&nxXytPY|)s

Explanation

GG  push input twice to stack
 &n  get size of matrix
 x  discard one of the two size numbers
 Xy get an identity matrix of that size
 t duplicate the identity matrix
 P flip one of the identty matrices
 Y| logical OR the two identity matrices
 ) perform (logical) indexing to the original matrix
 s compute the sum

Try it online!

MATL, (削除) 13 (削除ここまで) 11 bytes

This uses logical indexing. As an index we use an identity matrix of the size of the input and or it with it's flipped version, just like in my Octave answer. Thanks @LuisMendo for -2 bytes:)

tZyXytPY|)s

Explanation

t push input twice to stack
 Zy get size of matrix
 Xy get an identity matrix of that size
 t duplicate the identity matrix
 P flip one of the identty matrices
 Y| logical OR the two identity matrices
 ) perform (logical) indexing to the original matrix
 s compute the sum

Try it online!

Source Link
flawr
  • 44.1k
  • 7
  • 109
  • 253

MATL, 13 bytes

This uses logical indexing. As an index we use an identity matrix of the size of the input and or it with it's flipped version, just like in my Octave answer.

GG&nxXytPY|)s

Explanation

GG push input twice to stack
 &n get size of matrix
 x discard one of the two size numbers
 Xy get an identity matrix of that size
 t duplicate the identity matrix
 P flip one of the identty matrices
 Y| logical OR the two identity matrices
 ) perform (logical) indexing to the original matrix
 s compute the sum

Try it online!

AltStyle によって変換されたページ (->オリジナル) /