Drill

ProblemsGo › machines

Defects per thousand parts

easymachinesMathGo

Quality control reports scrapped parts as so many per thousand produced, truncated down.

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

Worked examples

CallResult
defectsPerThousand(500, 1000)500
defectsPerThousand(3, 10000)0
defectsPerThousand(1, 3)333
defectsPerThousand(2, 3)666

Hint

defects * 1000 / produced, guarding the divide by zero.

Reference solution in Go
func defectsPerThousand(defects int, produced int) int {
	if produced <= 0 {
		return 0
	}
	return defects*1000 / produced
}

The same problem in another language

More machines problems in Go