Last active
April 16, 2021 09:39
-
-
Save mesiriak/4b9a5075070166c4ea23f760fc78aefb to your computer and use it in GitHub Desktop.
Codewars. Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def path_finder(maze): | |
res = list(map(list,maze.split())) | |
res[0][0] = 0 | |
wasd = "" | |
a = 0 | |
moves = [(0,0)] | |
for move in moves: | |
y,x = move | |
if y+1 < len(res) and res[y+1][x] == ".": | |
res[y+1][x] = res[y][x] + 1 | |
moves.append((y+1,x)) | |
if y-1 >= 0 and res[y-1][x] == ".": | |
res[y-1][x] = res[y][x] + 1 | |
moves.append((y-1,x)) | |
if x+1 < len(res) and res[y][x+1] == ".": | |
res[y][x+1] = res[y][x] + 1 | |
moves.append((y,x+1)) | |
if x-1 >= 0 and res[y][x-1] == ".": | |
res[y][x-1] = res[y][x] + 1 | |
moves.append((y,x-1)) | |
for i in res: | |
print(i) | |
if res[len(res)-1][len(res)-1] != ".": | |
return True | |
else: | |
return False | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment