# Task

Given a square `matrix`, your task is to reverse the order of elements on both of its longest diagonals.

The longest diagonals of a square matrix are defined as follows:
* the first longest diagonal goes from the top left corner to the bottom right one;
* the second longest diagonal goes from the top right corner to the bottom left one.


# Example

For the matrix
```
1, 2, 3
4, 5, 6
7, 8, 9
```
the output should be:
```
9, 2, 7
4, 5, 6
3, 8, 1
```


# Input/Output


- `[input]` 2D integer array `matrix`

   Constraints: `1 ≤ matrix.length ≤ 10, matrix.length = matrix[i].length, 1 ≤ matrix[i][j] ≤ 1000`


- `[output]` 2D integer array

   Matrix with the order of elements on its longest diagonals reversed.

Difficulty: EASY
Starter code: def reverse_on_diagonals(matrix):
	

Solutions:
def reverse_on_diagonals(matrix):
	copy = [line[:] for line in matrix]
	for i in range(len(matrix)):
		copy[i][i] = matrix[-1 - i][-1 - i]
		copy[i][-1 - i] = matrix[-1 - i][i]
	return copy


def reverse_on_diagonals(matrix):
	l = len(matrix)
	for i in range(l // 2):
		j = l - i - 1
		(matrix[i][i], matrix[j][j]) = (matrix[j][j], matrix[i][i])
		(matrix[i][j], matrix[j][i]) = (matrix[j][i], matrix[i][j])
	return matrix


def reverse_on_diagonals(matrix):
	diag1 = [matrix[i][i] for i in range(len(matrix))]
	diag2 = [matrix[i][~i] for i in range(len(matrix))]
	for (i, n) in enumerate(reversed(diag1)):
		matrix[i][i] = n
	for (i, n) in enumerate(reversed(diag2)):
		matrix[i][~i] = n
	return matrix


from copy import deepcopy

def reverse_on_diagonals(matrix):
	matrix = deepcopy(matrix)
	n = len(matrix)
	for y in range(n // 2):
		x = n - y - 1
		(matrix[y][y], matrix[x][x]) = (matrix[x][x], matrix[y][y])
		(matrix[y][x], matrix[x][y]) = (matrix[x][y], matrix[y][x])
	return matrix


def reverse_on_diagonals(a):
	for i in range(len(a) // 2):
		j = -1 - i
		(a[i][i], a[j][j], a[i][j], a[j][i]) = (a[j][j], a[i][i], a[j][i], a[i][j])
	return a


def reverse_on_diagonals(mx):
	dl = []
	dr = []
	for i in range(len(mx)):
		dl.append(mx[i][i])
		dr.append(mx[i][-i - 1])
	for i in range(len(mx)):
		mx[i][i] = dl.pop()
		mx[i][-i - 1] = dr.pop()
	return mx


r = reversed
x = enumerate
reverse_on_diagonals = lambda m: [[f if i == j or len(m[i]) - (i + j + 1) == 0 else m[i][j] for (j, f) in x(e)] for (i, e) in x([list(r(e)) for e in r(m)])]


def reverse_on_diagonals(matrix):
	diagonals = [(row[idx], row[-idx - 1]) for (idx, row) in enumerate(matrix)]
	for (idx, ch) in enumerate(reversed(diagonals)):
		(matrix[idx][idx], matrix[idx][-idx - 1]) = ch
	return matrix


def reverse_on_diagonals(matrix):
	for i in range(int(len(matrix) / 2)):
		(matrix[i][i], matrix[len(matrix) - 1 - i][len(matrix) - 1 - i]) = (matrix[len(matrix) - 1 - i][len(matrix) - 1 - i], matrix[i][i])
		(matrix[len(matrix) - 1 - i][i], matrix[i][len(matrix) - 1 - i]) = (matrix[i][len(matrix) - 1 - i], matrix[len(matrix) - 1 - i][i])
	return matrix


def reverse_on_diagonals(matrix):
	n = len(matrix)
	for i in range(n // 2):
		(matrix[i][i], matrix[n - i - 1][n - i - 1]) = (matrix[n - i - 1][n - i - 1], matrix[i][i])
		(matrix[i][n - i - 1], matrix[n - i - 1][i]) = (matrix[n - i - 1][i], matrix[i][n - i - 1])
	return matrix