Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- matrix = np.random.randint(2, size=(10, 10))
- print(matrix)
- M, N = matrix.shape
- walked = []
- zonesCount = []
- def pathCount(x, y):
- if x < 0 or y < 0 or x >= M or y >= N:
- return 0
- if matrix[x, y] == 1: # I replaced * by 1 and . by 0 for easier generation
- return 0
- if (x, y) in walked:
- return 0
- walked.append((x, y))
- count = 1
- for i in [x - 1, x, x + 1]:
- for j in [y - 1, y, y + 1]:
- if (i, j) != (x, y):
- count += pathCount(i, j)
- return count
- for x in range(M):
- for y in range(N):
- if not (x, y) in walked:
- zonesCount.append(pathCount(x, y))
- print('Max zone count :', max(zonesCount))
- [[0 0 1 0 0 0 1 0 1 0]
- [1 0 1 0 0 0 1 0 1 1]
- [0 1 0 0 1 0 0 1 1 1]
- [0 0 1 0 0 0 1 1 0 1]
- [1 0 1 1 1 1 0 1 1 0]
- [1 0 1 1 1 1 0 1 1 0]
- [0 0 0 1 1 1 0 0 0 0]
- [1 0 0 1 1 0 0 1 1 0]
- [0 1 0 1 0 0 1 0 1 1]
- [0 1 1 0 0 0 1 0 1 0]]
- Max zone count : 50
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement