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 36 characters in body
Source Link
Business Cat
  • 9.2k
  • 1
  • 18
  • 37

CJam, 22(削除) 22 (削除ここまで) 21 bytes

Saved 1 byte thanks to Martin Ender

{_,({0\f+}*ee::m<z:m<:.+}

Anonymous block expecting the argument on the stack and leaves the result on the stack.

Try it online! Try it online!

How it works

_ e# Duplicate the matrix
 ,( e# Get its length (# of rows) minus 1
 {0\f+}* e# Prepend that many 0s to each row
 ee e# Enumerate; map each row to [index, row]
 ::m< e# Rotate each row left a number of spaces equal to its index
 z  e# Transpose the resulting matrix
 ::.+ e# Sum each row (of the transpose)column

CJam, 22 bytes

{_,({0\f+}*ee::m<z::+}

Anonymous block expecting the argument on the stack and leaves the result on the stack.

Try it online!

How it works

_ e# Duplicate the matrix
 ,( e# Get its length (# of rows) minus 1
 {0\f+}* e# Prepend that many 0s to each row
 ee e# Enumerate; map each row to [index, row]
 ::m< e# Rotate each row left a number of spaces equal to its index
 z  e# Transpose the resulting matrix
 ::+ e# Sum each row (of the transpose)

CJam, (削除) 22 (削除ここまで) 21 bytes

Saved 1 byte thanks to Martin Ender

{_,({0\f+}*ee::m<:.+}

Anonymous block expecting the argument on the stack and leaves the result on the stack.

Try it online!

How it works

_ e# Duplicate the matrix
 ,( e# Get its length (# of rows) minus 1
 {0\f+}* e# Prepend that many 0s to each row
 ee e# Enumerate; map each row to [index, row]
 ::m< e# Rotate each row left a number of spaces equal to its index
 :.+ e# Sum each column
Source Link
Business Cat
  • 9.2k
  • 1
  • 18
  • 37

CJam, 22 bytes

{_,({0\f+}*ee::m<z::+}

Anonymous block expecting the argument on the stack and leaves the result on the stack.

Try it online!

How it works

_ e# Duplicate the matrix
 ,( e# Get its length (# of rows) minus 1
 {0\f+}* e# Prepend that many 0s to each row
 ee e# Enumerate; map each row to [index, row]
 ::m< e# Rotate each row left a number of spaces equal to its index
 z e# Transpose the resulting matrix
 ::+ e# Sum each row (of the transpose)

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