Drill

ProblemsGo › production

How many batches to run

easyproductionMathGo

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

Go 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

func batchesNeeded(units int, perBatch int) int {
	
}

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 Go
func batchesNeeded(units int, perBatch int) int {
	if units <= 0 || perBatch <= 0 {
		return 0
	}
	return (units + perBatch - 1) / perBatch
}

The same problem in another language

More production problems in Go