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



We want to calculate the total sum for the matrix:



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!!

Source: codewars | Difficulty: EASY
Tags: Matrices

Fundamentals

Data structures

Mathematics

Starter code: def score_matrix(matrix):
	

Solutions:
def score_matrix(matrix):
	return sum(((-1) ** (i + j) * matrix[i][j] for i in range(len(matrix)) for j in range(len(matrix[i]))))


def score_matrix(matrix):
	return sum(((-1) ** (i + j) * x for (i, row) in enumerate(matrix) for (j, x) in enumerate(row)))


def score_matrix(matrix):
	total_sum = 0
	for (x, row) in enumerate(matrix):
		for (y, v) in enumerate(row):
			total_sum += v * (1 if (x + y) % 2 == 0 else -1)
	return total_sum


def score_matrix(matrix):
	return sum((sum((el if (row_idx + col_idx) % 2 == 0 else -el for (col_idx, el) in enumerate(row))) for (row_idx, row) in enumerate(matrix)))


score_matrix = lambda m: sum((y * [1, -1][i + j & 1] for (i, x) in enumerate(m) for (j, y) in enumerate(x)))


def score_matrix(matrix):
	res = 0
	for i in range(len(matrix)):
		for j in range(len(matrix[0])):
			if (i + j) % 2 == 0:
				res += matrix[i][j]
			else:
				res -= matrix[i][j]
	return res


def score_matrix(matrix):
	s = 0
	for (i, row) in enumerate(matrix):
		for (j, v) in enumerate(row):
			s += pow(-1, i + j) * v
	return s


(e, score_matrix) = (enumerate, lambda m: sum((c * (-1) ** (i + j) for (i, l) in e(m) for (j, c) in e(l))))