Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. n = 3 #matrix size
  2. f =[[0,1],[1,1]] #flower position
  3. w =[[0,0],[0,1],[2,1],[0,2]] #wall position
  4. i =[[0,3]] #ivy position
  5.  
  6. matrix = [["B" for x in range(n)] for x in range(n)]
  7. for row in matrix:
  8. for column in row:
  9. for item in f:
  10. matrix[item[0]][item[1]] = "F"
  11. for item in w:
  12. matrix[item[0]][item[1]] = "W"
  13.  
  14. def printMatrix():
  15. for _ in matrix:
  16. ln = ""
  17. for items in _:
  18. ln += items + " "
  19. print(ln)
  20.  
  21. def countB(matrix):
  22. n = len(matrix)
  23. for i in range(len(matrix)):
  24. for j in range(len(matrix[i])):
  25. if matrix[i][j] == "B":
  26. count = 0
  27. for x in range(i, n): #check right
  28. if matrix[x][j] == "F":
  29. count += 1
  30. if matrix[x][j] == "W":
  31. break
  32. for x in range(i, -1, -1): #check left
  33. if matrix[x][j] == "F":
  34. count += 1
  35. if matrix[x][j] == "W":
  36. break
  37. for y in range(j, n ,1): #check down
  38. if matrix[i][y] == "F":
  39. count += 1
  40. if matrix[i][y] == "W":
  41. break
  42. for y in range(j, -1, -1): #check up
  43. if matrix[i][y] == "F":
  44. count += 1
  45. if matrix[i][y] == "W":
  46. break
  47. if count >= 3:
  48. matrix[i][j] = str(count)
  49. else:
  50. matrix[i][j] = str(count)
  51.  
  52. printMatrix()
  53. countB(matrix)
  54. printMatrix()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement