Drill

ProblemsTypeScript › machines

Good parts per run cycle

easymachinesTypeScript

Each cycle a press makes partsPerCycle units and chips away scrapPerCycle of them. Count the good units over the whole run.

cycleOutput(cycles: int, partsPerCycle: int, scrapPerCycle: int) → int

Solve it in the editor →

Where you start

function cycleOutput(cycles: number, partsPerCycle: number, scrapPerCycle: number): number {
  
}

Worked examples

CallResult
cycleOutput(10, 5, 1)40
cycleOutput(0, 5, 1)0
cycleOutput(5, 3, 3)0
cycleOutput(5, 3, 5)0

Hint

Clamp the per-cycle good count at zero, then multiply by the cycles.

Reference solution in TypeScript
function cycleOutput(cycles: number, partsPerCycle: number, scrapPerCycle: number): number {
  const net = Math.max(0, partsPerCycle - scrapPerCycle);
  return cycles * net;
}

The same problem in another language

More machines problems in TypeScript