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 m600
# migrated from python 2.7
def check_connection(network, first, second):
x = []
for i in network:
x.append(i.split("-"))
y = []
for i in x:
if len(network) == 1 or ((i[0], i[1]) == (first, second) or (i[1], i[0]) == (first, second)):
return True
if i[0] == first:
y.append(i[1])
x = [a for a in x if a != i]
if i[1] == first:
y.append(i[0])
x = [a for a in x if a != i]
while y:
for i in y:
for j in x:
if j[0] == i:
if j[1] == second:
return True
y.append(j[1])
x = [a for a in x if a != j]
for j in x:
if j[1] == i:
if j[0] == second:
return True
y.append(j[0])
x = [a for a in x if a != j]
y.remove(i)
return False
June 19, 2015
Comments: