Drill

ProblemsC# › production

How many batches to run

easyproductionMathC#

The mixer takes a fixed number of units per batch, and a part-full batch still has to be run.

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.

Solve it in Python →

Where you start

public int BatchesNeeded(int units, int perBatch) {
    
}

Worked examples

CallResult
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;
}

The same problem in another language

More production problems in C#