Last active
April 16, 2021 09:39
-
-
Save mesiriak/7f887f4745ad91a85a93c1d28785d513 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 | |
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 == len(res)-1 and x == len(res)-1: | |
break | |
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 y == len(res)-1 and x+1 == len(res)-1: | |
break | |
if x-1 >= 0 and res[y][x-1] == ".": | |
res[y][x-1] = res[y][x] + 1 | |
moves.append((y,x-1)) | |
return res[len(res)-1][len(res)-1] if res[len(res)-1][len(res)-1] != "." else False | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment