Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Right Hand Rule solution in Clear category for Open Labyrinth by slickLash
DELTA_MOVE = {'S': (1, 0), 'N': (-1, 0), 'W': (0, -1), 'E': (0, 1)}
RIGHT_HAND_RULES = {'S': ('W', 'E'), 'N': ('E', 'W'),
'W': ('N', 'S'), 'E': ('S', 'N')}
def checkio(maze_map):
route = []
direction = 'S'
x, y = 1, 1
while not (x == y == 10):
move, turn = RIGHT_HAND_RULES[direction]
dx, dy = DELTA_MOVE[move]
nx, ny = x + dx, y + dy
if not maze_map[nx][ny]:
direction = move
route.append(direction)
x, y = nx, ny
else:
direction = turn
return ''.join(route)
March 8, 2015