Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
min(routes generator, key=len) solution in Clear category for Disposable Teleports by Phil15
def checkio(teleports_string):
""" Look for a route in teleport map. """ # V(ertices), E(dges)
V, E = set('12345678'), [set(e) for e in teleports_string.split(',')]
def routes(path):
last = path[-1]
if last == path[0] and set(path) == V:
yield path
for v in (a for a in V if {last, a} in E): # neighbors v of last.
if v + last not in path and last + v not in path:
yield from routes(path + v)
return min(routes('1'), key=len) # or just next(routes('1'))
Nov. 3, 2018
Comments: