Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Weak Point by Mahoter
def weak_point(matrix):
nrow = 0
ncol = 0
res = 101
a = 0
col_sum = []
for cnt in matrix:
col_sum += [0]
for row in matrix:
addit = 0
row = list(row)
b = 0
for num in row:
addit += num
col_sum[b] = col_sum[b] + num
b+=1
if addit < res:
res = addit
nrow = a
a += 1
res = 101
a = 0
for c in col_sum:
if c < res:
ncol = a
res = c
a += 1
ret = [nrow] + [ncol]
return ret
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. 17, 2016