Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Disposable Teleports by Moff
class SP(object):
def __init__(self, edges):
self.vertices = set()
for v1, v2 in edges:
self.vertices.add(v1)
self.vertices.add(v2)
self.solution = None
self.find_path(['1'], edges)
def check(self, path):
if path[0] == path[-1] and set(path) == self.vertices:
self.solution = path
def find_path(self, path, rest):
self.check(path)
if self.solution:
return
v = path[-1]
for i, (v1, v2) in enumerate(rest):
if v == v1:
self.find_path(path + [v2], rest[:i] + rest[i+1:])
if v == v2:
self.find_path(path + [v1], rest[:i] + rest[i+1:])
def checkio(source):
return ''.join(SP(source.split(',')).solution)
Aug. 14, 2015