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 wo.tomasz
def check_connection(network, first, second):
connected_drons = [first]
nl = list(network)
while len(nl) > 0 and len(connected_drons) > 0:
temp_con = []
i = len(nl) - 1
while i >= 0:
con = nl[i].split('-')
for d in connected_drons:
if con[0] == d:
temp_con.append(con[1])
nl.pop(i)
break
elif con[1] == d:
temp_con.append(con[0])
nl.pop(i)
break
i -= 1
if second in temp_con:
return True
connected_drons.clear()
connected_drons = temp_con.copy()
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. 26, 2020
Comments: