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 Sim0000
ETHERNET = (100, 40, 10, 1, 0.1) # Ethernet bandwidth capacity in Gbps
def checkio(ring, *flows):
# calculate traffics
n = len(ring)
traffics = [0]*n
for nodes, dr in flows:
# shortest path
i, j = (ring.index(nodes[i]) for i in (0, 1))
d = 2 * abs(i - j)
if d < n: i, j = min(i, j), max(i, j)
if d > n: i, j = max(i, j), min(i, j)
# flow aggregation
while i != j:
traffics[i] += dr
i = (i + 1) % n
# determine dimensions
m = len(ETHERNET)
dimensions = [0] * m
for traffic in traffics:
if traffic >= 100:
dimensions[0] -= -traffic // 100 # = -math.ceiling(traffic / 100)
elif traffic:
i = max(range(m), key=lambda i:traffic > ETHERNET[i]) - 1 # -1 if not found
dimensions[i] += 1
return dimensions
if __name__ == '__main__':
# These "asserts" are used only for self-checking and not necessary for auto-testing
assert checkio("AEFCBG", ("AC", 5), ("EC", 10), ("AB", 60)) == [2, 2, 1, 0, 0]
assert checkio("ABCDEFGH", ("AD", 4)) == [0, 0, 3, 0, 0]
assert checkio("ABCDEFGH", ("AD", 4), ("EA", 41)) == [4, 0, 3, 0, 0]
April 2, 2016