Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Open Labyrinth by Moff
class DepthFirstPaths(object):
def __init__(self, labyrinth, s):
self.field = labyrinth
self.paths = {s: ''}
self.dfs(s)
def adj(self, v):
row, col = v
moves = [('E', 0, 1), ('W', 0, -1), ('S', 1, 0), ('N', -1, 0)]
return [((row + dx, col + dy), move) for move, dx, dy in moves if self.field[row + dx][col + dy] == 0]
def dfs(self, v):
for w, move in self.adj(v):
if w not in self.paths:
self.paths[w] = self.paths[v] + move
self.dfs(w)
def checkio(field):
return DepthFirstPaths(field, (1, 1)).paths[(10, 10)]
July 23, 2015