Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Speedy category for Ethernet Ring Dimensioning by _Chico_
ETHERNET = (100, 40, 10, 1, 0.1) # Ethernet bandwidth capacity in Gbps
def checkio(ring, *flows):
ln = len(ring)
links = [0] * ln
for flow in flows:
start = ring.index(flow[0][0])
end = ring.index(flow[0][1])
ln_cw = (end - start) % ln
ln_ccw = (start - end) % ln
if ln_cw > ln_ccw:
start, end = end, start
i = start
while i != end:
links[i] += flow[1]
i = (i+1) % ln
bandwidths = [ min((x for x in ETHERNET if x >= l) ) for l in links if l != 0 and l<100 ] + \
[100] * int( sum([ (l//100 + (l%100>0) ) for l in links if l >100] ) )
return [bandwidths.count(x) for x in ETHERNET]
May 21, 2021