viligen

kates_way_out_multiarray

Oct 26th, 2021 (edited)
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. import numpy as np
  2.  
  3. rows = int(input())
  4.  
  5. row = []
  6. matrix = []
  7. index_kate = []
  8. count = 0
  9. is_move = False
  10. for r in range(rows):
  11.     row = list(input())
  12.     matrix.append(row)
  13. matrix = np.array(matrix)
  14.  
  15.  
  16. for r in range(rows):
  17.     for c in range(len(row)):
  18.         if matrix[r, c] == "k":
  19.             index_kate = [r, c]
  20.             break
  21. while index_kate[0] != rows - 1:
  22.     for r_ in range(index_kate[0], index_kate[0] + 2):
  23.         is_move = False
  24.         for c_ in range(index_kate[1] - 1, index_kate[1] + 2):
  25.             if c_ < 0 or c_ >= len(row):
  26.                 c_ = index_kate[1]
  27.  
  28.             if matrix[r_, c_] != "#" and matrix[r_, c_] != "k":
  29.                 index_kate = [r_, c_]
  30.                 matrix[r_, c_] = "k"
  31.                 is_move = True
  32.                 count += 1
  33.                 break
  34.         if is_move:
  35.             break
  36.     if not is_move:
  37.         break
  38.  
  39. if index_kate[0] != rows - 1:
  40.     print("Kate cannot get out")
  41. elif index_kate[0] == rows - 1:
  42.     count += 1
  43.     print(f"Kate got out in {count} moves")
  44.  
Add Comment
Please, Sign In to add comment