THINK FIRST·CODE LATER

← All labs

The review bottleneck: simulate agent PRs vs. human review

Problem

Agents can open pull requests faster than humans can review them. Simulate the review queue day by day.

Input: first line days reviewCapacity wipLimit. Second line: days integers — the number of PRs agents want to open on each day.

Each day, in this order:

  1. Arrivals: if wipLimit is 0 (no limit), all wanted PRs are added to the queue; otherwise agents may add PRs only while the queue is below wipLimit (so at most wipLimit - queue are added; the others are not created that day).
  2. Reviews: humans review up to reviewCapacity PRs from the front of the queue (oldest first). Each reviewed PR's waiting time is today - arrivalDay (0 if reviewed on the day it arrived).

Print for each day Day d: +added (wanted w), reviewed r, queue q. At the end print:

Reviewed: R, Still waiting: S
Average wait: x.xx days
Max queue: M

(average over reviewed PRs, two decimals; 0.00 if none; the maximum queue is the largest queue size measured right after the arrivals of a day).

Input:

5 10 0
30 30 30 5 5

Output:

Day 1: +30 (wanted 30), reviewed 10, queue 20
Day 2: +30 (wanted 30), reviewed 10, queue 40
Day 3: +30 (wanted 30), reviewed 10, queue 60
Day 4: +5 (wanted 5), reviewed 10, queue 55
Day 5: +5 (wanted 5), reviewed 10, queue 50
Reviewed: 50, Still waiting: 50
Average wait: 1.60 days
Max queue: 70

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

s14-4-data-1.txt

5 10 0
30 30 30 5 5
What your program must print for s14-4-data-1.txt
Day 1: +30 (wanted 30), reviewed 10, queue 20
Day 2: +30 (wanted 30), reviewed 10, queue 40
Day 3: +30 (wanted 30), reviewed 10, queue 60
Day 4: +5 (wanted 5), reviewed 10, queue 55
Day 5: +5 (wanted 5), reviewed 10, queue 50
Reviewed: 50, Still waiting: 50
Average wait: 1.60 days
Max queue: 70

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < s14-4-data-1.txt

Windows PowerShell does not understand <:

Get-Content s14-4-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.