Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
How to find friends solution in Clear category for How to Find Friends by djoker
def check_connection(network, first, second):
ynet={}
for s in network:
s1,s2=s.split('-')
if s1 not in ynet.keys():
ynet[s1]=[]
if s2 not in ynet.keys():
ynet[s2]=[]
ynet[s1].append(s2)
ynet[s2].append(s1)
f_test=True
while f_test:
f_test = False
for n in ynet.keys():
for e in ynet[n]:
for se in ynet[e]:
if se not in ynet[n]:
f_test =True
ynet[n].append(se)
return first in ynet[second]
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert check_connection(
("dr101-mr99", "mr99-out00", "dr101-out00", "scout1-scout2",
"scout3-scout1", "scout1-scout4", "scout4-sscout", "sscout-super"),
"scout2", "scout3") == True, "Scout Brotherhood"
assert check_connection(
("dr101-mr99", "mr99-out00", "dr101-out00", "scout1-scout2",
"scout3-scout1", "scout1-scout4", "scout4-sscout", "sscout-super"),
"super", "scout2") == True, "Super Scout"
assert check_connection(
("dr101-mr99", "mr99-out00", "dr101-out00", "scout1-scout2",
"scout3-scout1", "scout1-scout4", "scout4-sscout", "sscout-super"),
"dr101", "sscout") == False, "I don't know any scouts."
Aug. 7, 2014
Comments: