-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCentSever recursion_adj_matrix.py
44 lines (28 loc) · 1.06 KB
/
CentSever recursion_adj_matrix.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
40
41
42
43
44
import numpy as np
import sys
table = np.array([['1', '0', '0',],
['0', '0', '0',],
['0', '0', '1',]])
counter=[0]
print('starting:')
print(table)
def fill(CentServer, i, j, symbol):
if CentServer[i, j] != symbol:
originalSymbol = CentServer[i, j]
#return "Finished count %s" % counter
def r(i, j):
counter[0]+=1
if i < 0 or i >= CentServer.shape[0] or j < 0 or j >= CentServer.shape[1]:
# out of bounds
return
#change the symbol if r or c is adjacent
if CentServer[i,j] == originalSymbol:
CentServer[i,j] = symbol
for di, dj in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
r(i+di, j+dj)
r(i, j)
return CentServer
limit = sys.getrecursionlimit()
print('full update of servers:')
print(fill(table, 1, 1, '1'))
print("Recursion Limit:", limit," || number of days: ", counter[0])