How many batches to run
The mixer takes a fixed number of units per batch, and a part-full batch still has to be run.
- A leftover of even one unit needs a whole extra batch.
- A batch size of zero or less makes no sense: return 0.
- Nothing to make means no batches.
BatchesNeeded(units: int, perBatch: int) → int
C# needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.
Where you start
public int BatchesNeeded(int units, int perBatch) {
}
Worked examples
| Call | Result |
|---|---|
BatchesNeeded(100, 25) | 4 |
BatchesNeeded(101, 25) | 5 |
BatchesNeeded(1, 25) | 1 |
BatchesNeeded(0, 25) | 0 |
Hint
Ceiling division in integers: (units + perBatch - 1) / perBatch.
Reference solution in C#
public int BatchesNeeded(int units, int perBatch) {
if (units <= 0 || perBatch <= 0) return 0;
return (units + perBatch - 1) / perBatch;
}