0 out of 464 challenges solved
A **magic square** is a square matrix in which the sum of every row, column, and both main diagonals is the same. Write a function `is_magic_square(matrix)` that determines whether a given square matrix is a magic square.
#### Function Signature
```python [main.nopy]
def is_magic_square(matrix: list[list[int]]) -> bool:
pass
```
#### Input
- `matrix`: A list of lists of integers representing a square matrix (n x n).
#### Output
- Returns `True` if the matrix is a magic square, otherwise `False`.
#### Example Usage
```python [main.nopy]
is_magic_square([[2, 7, 6], [9, 5, 1], [4, 3, 8]]) # True
is_magic_square([[1, 2], [3, 4]]) # False
is_magic_square([[16, 2, 3, 13], [5, 11, 10, 8], [9, 7, 6, 12], [4, 14, 15, 1]]) # True
```
#### Constraints
- The input matrix will always be square (n x n).
- The matrix will contain only integers.def is_magic_square(matrix: list[list[int]]) -> bool:
"""
Determine if the given square matrix is a magic square.
Args:
matrix (list[list[int]]): A square matrix of integers.
Returns:
bool: True if the matrix is a magic square, False otherwise.
"""
# Placeholder for the solution
pass