Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def max_neighbor_sum(matrix):
- max_sum = float('-inf')
- rows = len(matrix)
- cols = max(len(row) for row in matrix)
- for i in range(rows - 1):
- for j in range(cols - 1):
- if i + 1 < rows and j + 1 < len(matrix[i]) and j + 1 < len(matrix[i + 1]):
- current_sum = (
- matrix[i][j] + matrix[i + 1][j] +
- matrix[i][j + 1] + matrix[i + 1][j + 1]
- )
- if current_sum > max_sum:
- max_sum = current_sum
- return max_sum
- input_matrix = [
- [1, 2, 200],
- [4],
- [5, 6],
- [7, 8, 9, 10],
- [1, 5],
- [12, 2, 3, 5, 5]
- ]
- result = max_neighbor_sum(input_matrix)
- print("Най-голямата сума на съседни точки в матрицата е:", result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement