Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Disposable Teleports by hyry
# migrated from python 2.7
def find_route(route, paths):
if len(set(route)) == 8 and route.endswith("1"):
yield route
else:
now_tel = route[-1]
connected_paths = {p for p in paths if now_tel in p}
for p in connected_paths:
next_tel = p.replace(now_tel, "")
paths.remove(p)
for r in find_route(route + next_tel, paths):
yield r
paths.add(p)
def checkio(teleports_string):
paths =teleports_string.split(",")
return next(find_route("1", set(paths)))
if __name__ == "__main__":
print((checkio("12,23,34,45,56,67,78,81"))) #"123456781"
print((checkio("12,28,87,71,13,14,34,35,45,46,63,65"))) #"1365417821"
print((checkio("12,15,16,23,24,28,83,85,86,87,71,74,56"))) #"12382478561"
print((checkio("13,14,23,25,34,35,47,56,58,76,68"))) #"132586741"
April 27, 2013
Comments: