Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
DFS solution in Clear category for Disposable Teleports by DiZ
def checkio(edges, vertices=8):
G, bag = set(map(frozenset, edges.split(','))), [('1', set())]
while bag:
path, used = bag.pop()
if path[-1] == '1' and len(set(path)) == vertices:
return ''.join(path)
for v in map(str, range(1, vertices+1)):
edge = frozenset({v, path[-1]})
if edge in G-used:
bag.append((path+v, used|{edge}))
Aug. 29, 2014