Drill

ProblemsPython › machines

Good parts per run cycle

easymachinesPython

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

cycle_output(cycles: int, parts_per_cycle: int, scrap_per_cycle: int) → int

Solve it in the editor →

Where you start

def cycle_output(cycles: int, parts_per_cycle: int, scrap_per_cycle: int) -> int:
    

Worked examples

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

Hint

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

Reference solution in Python
def cycle_output(cycles: int, parts_per_cycle: int, scrap_per_cycle: int) -> int:
    net = max(0, parts_per_cycle - scrap_per_cycle)
    return cycles * net

The same problem in another language

More machines problems in Python