Drill

ProblemsGo › finance

Price per unit

easyfinanceMathGo

A bulk bin lists a total for a quantity of identical items. What does a single unit cost?

pricePerUnit(totalMinor: int, quantity: 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 pricePerUnit(totalMinor int, quantity int) int {
	
}

Worked examples

CallResult
pricePerUnit(1000, 4)250
pricePerUnit(1000, 3)333
pricePerUnit(100, 10)10
pricePerUnit(0, 5)0

Hint

Divide and drop the remainder.

Reference solution in Go
func pricePerUnit(totalMinor int, quantity int) int {
	if quantity <= 0 {
		return 0
	}
	return totalMinor / quantity
}

The same problem in another language

More finance problems in Go