Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = 3 #matrix size
- f =[[0,1],[1,1]] #flower position
- w =[[0,0],[0,1],[2,1],[0,2]] #wall position
- i =[[0,3]] #ivy position
- matrix = [["B" for x in range(n)] for x in range(n)]
- for row in matrix:
- for column in row:
- for item in f:
- matrix[item[0]][item[1]] = "F"
- for item in w:
- matrix[item[0]][item[1]] = "W"
- def printMatrix():
- for _ in matrix:
- ln = ""
- for items in _:
- ln += items + " "
- print(ln)
- def countB(matrix):
- n = len(matrix)
- for i in range(len(matrix)):
- for j in range(len(matrix[i])):
- if matrix[i][j] == "B":
- count = 0
- for x in range(i, n): #check right
- if matrix[x][j] == "F":
- count += 1
- if matrix[x][j] == "W":
- break
- for x in range(i, -1, -1): #check left
- if matrix[x][j] == "F":
- count += 1
- if matrix[x][j] == "W":
- break
- for y in range(j, n ,1): #check down
- if matrix[i][y] == "F":
- count += 1
- if matrix[i][y] == "W":
- break
- for y in range(j, -1, -1): #check up
- if matrix[i][y] == "F":
- count += 1
- if matrix[i][y] == "W":
- break
- if count >= 3:
- matrix[i][j] = str(count)
- else:
- matrix[i][j] = str(count)
- printMatrix()
- countB(matrix)
- printMatrix()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement