7 kyu

#1 Matrices : Making an Alternating Sum

440 of 994raulbc777

Description:

We have a matrix of integers with m rows and n columns.

(a11a12a1na21a22a2nam1am2amn)\begin{pmatrix} a_{11} & a_{12} & \cdots &a_{1n} \\ a_{21} & a_{22} &\cdots &a_{2n} \\ \cdots & \cdots & \cdots & \cdots \\ \cdots & \cdots & \cdots & \cdots \\ a_{m1} & a_{m2} & \cdots &a_{mn} \end{pmatrix}

We want to calculate the total sum for the matrix:

i=1mj=1n(1)i+jaij\displaystyle\sum_{i=1}^{m} \sum_{j=1}^{n} (-1)^{i+j}a_{ij}

As you can see, the name "alternating sum" of the title is due to the sign of the terms that changes from one term to its contiguous one and so on.

Let's see an example:

matrix = [[1, 2, 3], [-3, -2, 1], [3, - 1, 2]]

total_sum = (1 - 2 + 3) + [-(-3) + (-2) - 1] + [3 - (-1) + 2] = 2 + 0 + 6 = 8

You may be given matrixes with their dimensions between these values:10 < m < 300 and 10 < n < 300.

More example cases in the Example Test Cases. Enjoy it!!

Fundamentals
Data Structures
Algorithms
Mathematics
Logic
Matrix

Stats:

CreatedApr 27, 2016
PublishedApr 27, 2016
Warriors Trained1851
Total Skips42
Total Code Submissions2666
Total Times Completed994
Python Completions440
JavaScript Completions453
Ruby Completions61
C Completions85
Julia Completions11
Total Stars37
% of votes with a positive feedback rating87% of 203
Total "Very Satisfied" Votes161
Total "Somewhat Satisfied" Votes33
Total "Not Satisfied" Votes9
Ad
Contributors
  • raulbc777 Avatar
  • donaldsebleung Avatar
  • rowcased Avatar
  • FArekkusu Avatar
  • user9644768 Avatar
  • stellartux Avatar
Ad