Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
New Cities solution in Uncategorized category for New Cities by vvm70
def subnetworks(net, crushes):
[net[i].remove(c) for c in crushes for i in range(len(net)) if c in net[i]]
[net.remove(c) for c in net if not c]
s = []
while net:
s.append(set(net.pop(0)))
while [y for y in net if s[-1] & set(y)]:
for x in [y for y in net if s[-1] & set(y)]:
s[-1] |= set(net.pop(net.index(x)))
return len(s)
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert subnetworks([
['A', 'B'],
['B', 'C'],
['C', 'D']
], ['B']) == 2, "First"
assert subnetworks([
['A', 'B'],
['A', 'C'],
['A', 'D'],
['D', 'F']
], ['A']) == 3, "Second"
assert subnetworks([
['A', 'B'],
['B', 'C'],
['C', 'D']
], ['C', 'D']) == 1, "Third"
print('Done! Check button is waiting for you!')
June 19, 2020