Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Open Labyrinth solution in Uncategorized category for Open Labyrinth by capback250
COORDS = ((-1, 0), (0, -1), (0, 1), (1, 0))
def graf_builder(array):
n = {}
for x in range(1,11):
for y in range(1,11):
if array[x][y] == 0:
n[str([x, y])] = core(array, x, y)
return n
def core(array, x, y):
neibors = set()
for c in COORDS:
dx, dy = x + c[0], y + c[1]
if array[dx][dy] == 0:
neibors.add(str([dx, dy]))
return neibors
def dfs_paths(graph, start, goal):
stack = [(start, [start])]
while stack:
(vertex, path) = stack.pop()
for next in graph[vertex] - set(path):
if next == goal:
yield path + [next]
else:
stack.append((next, path + [next]))
def navigator(string):
ways = {str([1, 0]):"S", str([-1, 0]):"N", str([0, 1]):"E", str([0, -1]):"W" }
way = ''
for x in range(len(string)-1):
c = str([int(string[x+1][1:-1].split(',')[0]) - int(string[x][1:-1].split(',')[0]), int(string[x+1][1:-1].split(',')[1]) - int(string[x][1:-1].split(',')[1])])
way += ways[c]
return way
def checkio(array):
#min_path = min(map(lambda x: len(x), dfs_paths(graf_builder(array), str([1, 1]), str([10, 10]))))
for string in dfs_paths(graf_builder(array), str([1, 1]), str([10, 10])):
#if len(string) == min_path:
return navigator(string)
Nov. 6, 2015