Nov-13-2019, 11:35 AM
Hi,
this is text of exercise:
I tried to break it down by thinking if I had a list rather than a matrix:
if I had only one list and had to change the element with a value of 0 to 1 I found this solution that works and returns a list with all the values 1
But how do I get a matrix and then "calculate" how long it takes for it to become all of them?
this is text of exercise:
Quote:Given a 2D grid, each cell is either a zombie 1 or a human 0. Zombies can turn adjacent (up / down / left / right) human beings into zombies every hour. Find out how many hours does it take to infect all humans?I haven't found many resources on the 2d matrices in python ,so
I tried to break it down by thinking if I had a list rather than a matrix:
if I had only one list and had to change the element with a value of 0 to 1 I found this solution that works and returns a list with all the values 1
a = [0,1,1,0,1] contagion = [1 if x == 0 else x for x in a] print(contagion)It also works for others (I did the tests)
But how do I get a matrix and then "calculate" how long it takes for it to become all of them?