Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
How to Find Friends solution in Uncategorized category for How to Find Friends by vvm70
def check_connection(network, first, second):
net = list({tuple(x.split('-')) for x in network})
nodes = {x for y in {net.pop(net.index(x)) for x in net if first in x} for x in y}
while {y for y in net if nodes & set(y)}:
for x in {y for y in net if nodes & set(y)}:
nodes |= set(net.pop(net.index(x)))
return second in nodes
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."
June 19, 2020