Drill

ProblemsPython › production

How many batches to run

easyproductionPython

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

batches_needed(units: int, per_batch: int) → int

Solve it in the editor →

Where you start

def batches_needed(units: int, per_batch: int) -> int:
    

Worked examples

CallResult
batches_needed(100, 25)4
batches_needed(101, 25)5
batches_needed(1, 25)1
batches_needed(0, 25)0

Hint

Ceiling division in integers: (units + perBatch - 1) / perBatch.

Reference solution in Python
def batches_needed(units: int, per_batch: int) -> int:
    if units <= 0 or per_batch <= 0:
        return 0
    return (units + per_batch - 1) // per_batch

The same problem in another language

More production problems in Python