Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Done solution in Clear category for Network Attack by nikita.dzhigir
def capture(matrix):
comps = {0: 0}
views = []
minutes = 0
while True:
for i in list(comps.keys()):
comps[i] = comps[i] - 1 if comps[i] > 0 else 0
if i not in views and comps[i] == 0:
for j, v in enumerate(matrix[i]):
if v == 1 and j not in comps.keys():
comps[j] = matrix[j][j]
views.append(i)
if any(comps.values()):
minutes += 1
continue
else:
return minutes
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert capture([[0, 1, 0, 1, 0, 1],
[1, 8, 1, 0, 0, 0],
[0, 1, 2, 0, 0, 1],
[1, 0, 0, 1, 1, 0],
[0, 0, 0, 1, 3, 1],
[1, 0, 1, 0, 1, 2]]) == 8, "Base example"
assert capture([[0, 1, 0, 1, 0, 1],
[1, 1, 1, 0, 0, 0],
[0, 1, 2, 0, 0, 1],
[1, 0, 0, 1, 1, 0],
[0, 0, 0, 1, 3, 1],
[1, 0, 1, 0, 1, 2]]) == 4, "Low security"
assert capture([[0, 1, 1],
[1, 9, 1],
[1, 1, 9]]) == 9, "Small"
Oct. 30, 2018