Drill

ProblemsGo › production

Defects per million parts

easyproductionMathGo

Quality reports the defect rate in parts per million, because "0.03%" is harder to compare across lines than "300 ppm".

defectPpm(defects: int, produced: 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 defectPpm(defects int, produced int) int {
	
}

Worked examples

CallResult
defectPpm(3, 10000)300
defectPpm(0, 10000)0
defectPpm(1, 3)333333
defectPpm(2, 3)666667

Hint

defects * 1000000 / produced, with half the divisor added before dividing so it rounds instead of truncating.

Reference solution in Go
func defectPpm(defects int, produced int) int {
	if produced <= 0 {
		return 0
	}
	return (defects*1000000 + produced/2) / produced
}

The same problem in another language

More production problems in Go