Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Recursive solution in Clear category for How to Find Friends by Eldin
from copy import copy
def check_connection(network, first, second):
friendlist = [sorted(x.split("-")) for x in network]
return check(friendlist,first,second)
def check(list, first, second):
for x in range(len(list)-1,-1,-1):
connection = copy(list[x])
if first in connection:
if second in connection:
return True
else:
connection.pop(connection.index(first))
if check(list[:x]+list[x+1:], connection[0], second):
return True
return False
Dec. 2, 2014
Comments: