Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- rows = int(input())
- row = []
- matrix = []
- index_kate = []
- count = 0
- is_move = False
- for r in range(rows):
- row = list(input())
- matrix.append(row)
- matrix = np.array(matrix)
- for r in range(rows):
- for c in range(len(row)):
- if matrix[r, c] == "k":
- index_kate = [r, c]
- break
- while index_kate[0] != rows - 1:
- for r_ in range(index_kate[0], index_kate[0] + 2):
- is_move = False
- for c_ in range(index_kate[1] - 1, index_kate[1] + 2):
- if c_ < 0 or c_ >= len(row):
- c_ = index_kate[1]
- if matrix[r_, c_] != "#" and matrix[r_, c_] != "k":
- index_kate = [r_, c_]
- matrix[r_, c_] = "k"
- is_move = True
- count += 1
- break
- if is_move:
- break
- if not is_move:
- break
- if index_kate[0] != rows - 1:
- print("Kate cannot get out")
- elif index_kate[0] == rows - 1:
- count += 1
- print(f"Kate got out in {count} moves")
Add Comment
Please, Sign In to add comment