32 lines
1.2 KiB
Python
32 lines
1.2 KiB
Python
|
def calculate_line_sum(matrix):
|
||
|
min_sum = 10000
|
||
|
current_line_index = 0
|
||
|
i = 0
|
||
|
for line in matrix:
|
||
|
current_line_index = i if min_sum > sum(line) else current_line_index
|
||
|
min_sum = sum(line) if min_sum > sum(line) else min_sum
|
||
|
i += 1
|
||
|
return current_line_index
|
||
|
|
||
|
|
||
|
def weak_point(matrix):
|
||
|
return calculate_line_sum(matrix), calculate_line_sum(list(zip(*matrix[::-1]))) # [0, 0]
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
# These "asserts" using only for self-checking and not necessary for auto-testing
|
||
|
assert isinstance(weak_point([[1]]), (list, tuple)), "The result should be a list or a tuple"
|
||
|
assert list(weak_point([[7, 2, 7, 2, 8],
|
||
|
[2, 9, 4, 1, 7],
|
||
|
[3, 8, 6, 2, 4],
|
||
|
[2, 5, 2, 9, 1],
|
||
|
[6, 6, 5, 4, 5]])) == [3, 3], "Example"
|
||
|
assert list(weak_point([[7, 2, 4, 2, 8],
|
||
|
[2, 8, 1, 1, 7],
|
||
|
[3, 8, 6, 2, 4],
|
||
|
[2, 5, 2, 9, 1],
|
||
|
[6, 6, 5, 4, 5]])) == [1, 2], "Two weak point"
|
||
|
assert list(weak_point([[1, 1, 1],
|
||
|
[1, 1, 1],
|
||
|
[1, 1, 1]])) == [0, 0], "Top left"
|