Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Ethernet Ring Dimensioning by flpo
ETHERNET = (.1, 1, 10, 40, 100)
def checkio(nodes, *flows):
connections = {frozenset(nodes[i:i+2]): 0 for i in range(len(nodes) - 1)}
connections[frozenset((nodes[0], nodes[-1]))] = 0
nodes2 = nodes*2
for (start, end), gb in flows:
i = nodes.index(start)
j = nodes2.index(end, i)
path = min(nodes2[i:j + 1], nodes2[j:i + len(nodes) + 1], key=len)
for i in range(len(path) - 1):
connections[frozenset(path[i:i+2])] += gb
result = [0] * 5
for gb in filter(None, connections.values()):
if gb > 100:
result[-1] -= -gb//100
else:
result[next(i for i, j in enumerate(ETHERNET) if gb <= j)] += 1
return result[::-1]
Aug. 21, 2017