Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Weak Point by MartynaDziubalka
def weak_point(matrix):
min_row_sum = 100000
min_col_sum = 100000
row_index = 0
col_index = 0
for x in range(0, len(matrix)):
current_row_sum = 0
current_col_sum = 0
for y in range(0, len(matrix[x])):
current_row_sum += matrix[x][y]
current_col_sum += matrix[y][x]
if current_row_sum < min_row_sum:
min_row_sum = current_row_sum
row_index = x
if current_col_sum < min_col_sum:
min_col_sum = current_col_sum
col_index = x
return [row_index, col_index]
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"
Jan. 28, 2016