Skip to main content
added 1199 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

MATL, 19 bytes

,!ix"0GYs@12XQ!g]v! 

Inputs are M (matrix), H (column vector), V (column vector). The row separator is ;.

Try it online! Or verify all test cases: 1, 2, 3, 4, 5.

Explanation

I'll add an explanation tomorrow later. This does the cumulative sum horizontally, then vertically.

, % Do the following twice ! % First time this inputs M implicitly. Transpose. Second time % it transposes the result of the horizontal cumulative sum ix % Input H (first time) or V (second time). Delete it; but gets % copied into clipboard G " % For each column of the matrix 0G % Push most recent input: H (first time) or V (second) Ys % Cumulative sum. This produces a vector of integer values % such that all columns (first time) or rows (second) of M % with the same value in this vector should be cumulatively % summed @ % Push current column of M transposed (first time) or M after % horizontal cumulative sum (second time) 12XQ % Cumulative sum. Gives a cell array of row vectors !g % Join those vectors into one row vector ] % End v % Concatenate the row vectors vertically into a matrix ! % Transpose. This corrects for the fact that each column vector % of the matrix was cumulatively summed into a row vector % Implicit end. Implicit display 

MATL, 19 bytes

,!ix"0GYs@12XQ!g]v! 

Inputs are M (matrix), H (column vector), V (column vector). The row separator is ;.

Try it online! Or verify all test cases: 1, 2, 3, 4, 5.

I'll add an explanation tomorrow later.

MATL, 19 bytes

,!ix"0GYs@12XQ!g]v! 

Inputs are M (matrix), H (column vector), V (column vector). The row separator is ;.

Try it online! Or verify all test cases: 1, 2, 3, 4, 5.

Explanation

This does the cumulative sum horizontally, then vertically.

, % Do the following twice ! % First time this inputs M implicitly. Transpose. Second time % it transposes the result of the horizontal cumulative sum ix % Input H (first time) or V (second time). Delete it; but gets % copied into clipboard G " % For each column of the matrix 0G % Push most recent input: H (first time) or V (second) Ys % Cumulative sum. This produces a vector of integer values % such that all columns (first time) or rows (second) of M % with the same value in this vector should be cumulatively % summed @ % Push current column of M transposed (first time) or M after % horizontal cumulative sum (second time) 12XQ % Cumulative sum. Gives a cell array of row vectors !g % Join those vectors into one row vector ] % End v % Concatenate the row vectors vertically into a matrix ! % Transpose. This corrects for the fact that each column vector % of the matrix was cumulatively summed into a row vector % Implicit end. Implicit display 
added 13 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

MATL, 19 bytes

,!ix"0GYs@12XQ!g]v! 

Inputs are M (matrix), H (column vector), V (column vector). The row separator is ;.

Try it online! Or verify all test cases: 1, 2, 3, 4, 5.

I'll add an explanation tomorrowtomorrow later.

MATL, 19 bytes

,!ix"0GYs@12XQ!g]v! 

Inputs are M (matrix), H (column vector), V (column vector). The row separator is ;.

Try it online! Or verify all test cases: 1, 2, 3, 4, 5.

I'll add an explanation tomorrow.

MATL, 19 bytes

,!ix"0GYs@12XQ!g]v! 

Inputs are M (matrix), H (column vector), V (column vector). The row separator is ;.

Try it online! Or verify all test cases: 1, 2, 3, 4, 5.

I'll add an explanation tomorrow later.

added 39 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

MATL, 19 bytes

,!ix"0GYs@12XQ!g]v! 

Inputs are M (matrix), H (column vector), V (column vector). The row separator is ;.

Try it online! Or verify all test cases: 1, 2, 3, 4, 5.

I'll add an explanation tomorrow.

MATL, 19 bytes

,!ix"0GYs@12XQ!g]v! 

Inputs are M (matrix), H (column vector), V (column vector). The row separator is ;.

Try it online! Or verify all test cases: 1, 2, 3, 4, 5.

MATL, 19 bytes

,!ix"0GYs@12XQ!g]v! 

Inputs are M (matrix), H (column vector), V (column vector). The row separator is ;.

Try it online! Or verify all test cases: 1, 2, 3, 4, 5.

I'll add an explanation tomorrow.

deleted 7 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading
deleted 23 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading
added 917 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading
added 917 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading