Skip to content

Instantly share code, notes, and snippets.

@mesiriak
Last active April 16, 2021 09:39
Show Gist options
  • Save mesiriak/4b9a5075070166c4ea23f760fc78aefb to your computer and use it in GitHub Desktop.
Save mesiriak/4b9a5075070166c4ea23f760fc78aefb to your computer and use it in GitHub Desktop.
Codewars. Python
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