Stop-and-wait utilisation

Stop-and-wait sends one packet and waits a whole round trip for its ACK. How much of the time is the link really sending?

What to build

A program that computes the share of time a stop-and-wait sender spends transmitting.

Requirements

  • Work out the transmission time t of one packet in milliseconds.
  • The sender is busy for t out of every rtt + t milliseconds. Print utilisation P% with P = 100 × t ÷ (rtt + t) to 2 decimal places.

Input

One line: the packet size in bytes, the link rate in Mbps and the round-trip time in ms.

Output

One line like utilisation 2.60%.

Constraints

All numbers are positive decimals; the round-trip time may be 0.

Example

Input:

1000 1000 30

Output:

utilisation 0.03%

Why it works

After a packet is sent, the sender waits one round trip for the ACK, so one cycle takes t + rtt. Only t of that is sending, so a long round trip or a fast link makes the share tiny.

Examples

Example 1 · Input
1000 1000 30
Expected output
utilisation 0.03%
Example 2 · Input
1500 10 0
Expected output
utilisation 100.00%

Prompts inside input() are ignored when checking, so input("n: ") is fine.

Hints

Hint 1

Transmission time in ms = bytes * 8 / (rate_mbps * 1000).

Hint 2

Utilisation = t / (rtt + t), where t is the transmission time and rtt the round-trip time, both in ms.

Hint 3

Print it as a percentage with 2 decimals.

Solution

Show one correct solution (try it yourself first)
size, rate, rtt = map(float, input().split())
t = size * 8 / (rate * 1000)
print(f"utilisation {100 * t / (rtt + t):.2f}%")

▶ Open this solution in the compiler, then press Visualize to watch it run step by step

Lesson: Reliable delivery: Go-Back-N and Selective Repeat →