Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Network Attack by kurosawa4434
def capture(matrix):
time_cnt = 0
pc_hp = [row[pc] for pc, row in enumerate(matrix)]
while sum(pc_hp) > 0:
time_cnt += 1
attacked_pc = []
for virus_pc in [pc for pc, remain_hp in enumerate(pc_hp) if remain_hp == 0]:
for target_pc in [pc for pc, net in enumerate(matrix[virus_pc]) if net and pc not in attacked_pc]:
pc_hp[target_pc] = (max(0, pc_hp[target_pc] - 1))
attacked_pc.append(target_pc)
return time_cnt
July 16, 2016