-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcontagious.py
39 lines (34 loc) · 1.11 KB
/
contagious.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def answer(population, x, y, strength):
if population[y][x]== -1:
return
if population[y][x] > strength:
return population
else:
population[y][x] = -1
if x > 0:
answer(population, x-1, y, strength)
if x < len(population[0])-1:
answer(population, x+1, y, strength)
if y > 0:
answer(population, x, y-1, strength)
if y < len(population)-1:
answer(population, x, y+1, strength)
return population
print answer([[2,2],[2,2]], 0, 0, 1)
print answer([[2,2],[2,2]], 0, 0, 3)
print answer([[1,2,3],[2,3,4],[3,2,1]], 0,0,2)
# if population[y][x]== -1:
# return
# if population[y][x] > strength:
# return population
# else:
# population[y][x] = -1
# if x > 0:
# answer(population, x-1, y, strength)
# if x < len(population[0])-1:
# answer(population, x+1, y, strength)
# if y > 0:
# answer(population, x, y-1, strength)
# if y < len(population)-1:
# answer(population, x, y+1, strength)
# return population