Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for How to Find Friends by Gabbek
def check_connection(network, first, second):
end = set([second])
visited = set()
explore = set([first])
while len(explore) > 0:
explore_element = set([explore.pop()])
add_explore = set()
for n in network:
n = set(n.split('-'))
if explore_element <= n and n-visited == n:
add_explore = add_explore|(n-explore_element)
if end <= add_explore:
return True
visited = visited|explore_element
explore = explore|add_explore
return False
Oct. 4, 2015