Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Simple solution with recursion solution in Clear category for Node Disconnected Users by bartosz_lyzwa
def is_entire_in_list(smaller_list, larger_list):
entire_in_list = True
for i in range(len(smaller_list)):
if smaller_list[i] not in larger_list:
entire_in_list = False
break;
return entire_in_list
def find_connected_cities(source, net, crushes):
connected = []
for i in range(len(net)):
if source in net[i]:
if net[i][0] == source:
if net[i][1] not in crushes:
connected += net[i][1]
else:
if net[i][0] not in crushes:
connected += net[i][0]
return connected
def create_list_of_connected(recived, net, source, crushes):
connected = find_connected_cities(source, net, crushes)
if not is_entire_in_list(connected, recived):
recived += connected
for i in range(len(connected)):
create_list_of_connected(recived, net, connected[i], crushes)
def disconnected_users(net, users, source, crushes):
received = []
if source not in crushes:
received += source
create_list_of_connected(received, net, source, crushes)
all_cities = list(users.keys())
not_received_cities = list(filter(lambda city: city not in received, all_cities))
not_received_people = 0
for i in range(len(not_received_cities)):
not_received_people += users[not_received_cities[i]]
return not_received_people
Oct. 21, 2017