Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Network Attack by Andreas_Strus
def capture(matrix):
names = [] #przechowuje informacje, czy infekcja się rozpoczęła
times = [] #przechowuj czasy pozostałe do końca infekcji
t = 0 #przechowuje czas jaki upłynął
for i in range(0,len(matrix)):
if i == 0:
names = names + [1]
else:
names = names + [0]
times = times +[matrix[i][i]]
while (times.count(0) != len(times)):
n = []
for i in range(len(matrix)):
if names[i] == 0:
for j in range(len(matrix)):
if i != j:
if matrix[i][j] == 1:
if names[j] == 1 and times[j] == 0:
n = n +[i]
for i in list(n):
names[i] = 1
for i in range(0,len(matrix)):
if names[i] == 1:
if times [i] > 0:
times[i] = times[i] - 1
t = t + 1
return t
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. 21, 2016