Drill

ProblemsC# › machines

Good parts per run cycle

easymachinesMathC#

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

C# 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

public int CycleOutput(int cycles, int partsPerCycle, int scrapPerCycle) {
    
}

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 C#
public int CycleOutput(int cycles, int partsPerCycle, int scrapPerCycle) {
    int net = Math.Max(0, partsPerCycle - scrapPerCycle);
    return cycles * net;
}

The same problem in another language

More machines problems in C#