Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for How to Find Friends by slygoblin
def check_connection(network, first, second):
names = [first]
while True:
counter = 0
for n in names:
for m in network:
if n == m.split("-")[0] and m.split("-")[1] not in names:
names.append(m.split("-")[1])
counter += 1
elif n == m.split("-")[1] and m.split("-")[0] not in names:
names.append(m.split("-")[0])
counter += 1
else:
continue
if second in names:
return True
if counter == 0:
return False
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."
Dec. 11, 2015