Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
12-liner: path-finding neighbor friends solution in Clear category for How to Find Friends by Stensen
def check_connection(conn, a, b):
visited, neighbr = {a}, [a]
while neighbr:
fore = neighbr.pop()
if fore == b: return True
for i in conn:
if fore in i:
i = i.replace(fore, '').replace('-', '')
if i not in visited:
neighbr.append(i)
visited.add(i)
return False
Nov. 20, 2020
Comments: