Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Disposable Teleports by kurosawa4434
ALL_STATION = set([str(n) for n in range(1, 9)])
def checkio(teleports_string):
teleports = teleports_string.split(',')
def route_search(rest=teleports, place='1', route=['1']):
if set(route) >= ALL_STATION and route[-1] == '1':
return True, route
for i, tp in enumerate(rest):
if place in tp:
next_place = tp[0] if place == tp[1] else tp[1]
rs, new_route = route_search(rest[:i]+rest[i+1:], next_place, route+[next_place])
if rs:
return True, new_route
return False, route
_, route = route_search()
return ''.join(route)
July 17, 2016