Skip to content

Instantly share code, notes, and snippets.

@trsqxyz
Last active August 29, 2015 13:56
Show Gist options
  • Save trsqxyz/9241499 to your computer and use it in GitHub Desktop.
Save trsqxyz/9241499 to your computer and use it in GitHub Desktop.
open-labyrinth
def checkio(maze_map):
direction = "S"
sr = {"N": ("WNES", (-1, 0)), # search routine, motion
"E": ("NESW", (0, 1)),
"S": ("ESWN", (1, 0)),
"W": ("SWNE", (0, -1))
}
pos = (1,1)
path = ""
def check_way(maze_map):
nonlocal sr, direction, pos
routine = sr.get(direction)[0]
for r in routine:
motion = sr.get(r)[1]
pos[0], pos[1] = pos[0] + motion[0], pos[1] + motion[1]
if maze_map[x][y] == 0: return r
while True:
direction= check_way(maze_map)
path += direction
if pos == (10, 10): return "".join(str(path))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment