Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. import numpy as np
  2. def countMine(mat, n):
  3. rows = n
  4. columns = n
  5. #lista = ['#' if elem=='#' else 0 for elem in [item for item in mat ]]
  6. bombs=[]
  7. for i in range(len(mat)):
  8. for j in range(len(mat[i])):
  9. if mat[i][j]=='#':
  10. bombs.append((i,j));
  11. filed = [[0 for i in range(columns)] for j in range(rows)]
  12. for bomb_location in bombs:
  13. (bomb_row, bomb_col) = bomb_location
  14. filed[bomb_row][bomb_col] = '#'
  15.  
  16. row_range = range(bomb_row - 1, bomb_row + 2)
  17. col_range = range(bomb_col - 1, bomb_col + 2)
  18.  
  19. for i in row_range:
  20. for j in col_range:
  21. if (0<=i<rows and 0<=j<columns and filed[i][j] != '#'):
  22. filed[i][j] +=1
  23. return filed
  24.  
  25.  
  26.  
  27. def main():
  28.  
  29. n=int(input())
  30. matrica = []
  31. for i in range(n):
  32. matrica.append([])
  33. list = input().split(" ")
  34. for j in range(n):
  35. matrica[i].append(list[j])
  36.  
  37. nova_mat = countMine(matrica, n)
  38. for i in range(len(nova_mat)):
  39. print(" ".join(map(str,nova_mat[i])))
  40. #print(nova_mat[i])
  41.  
  42.  
  43. if __name__ == "__main__":
  44. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement