All problems
One Cycle Peak Fraction
Problem
A one-cycle schedule rises linearly from 0 to peak_step and falls linearly from peak_step to total, never below zero.
Given t, peak_step, and total (with 0 < peak_step <= total), return the cycle fraction max(0, ...) where it is t / peak_step on the way up and (total - t) / (total - peak_step) on the way down.
Hint
Two linear branches sharing the peak at t = peak_step.
Test cases
case 1
in: [10,20,100]
expected: 0.5
case 2
in: [30,20,100]
expected: 0.875
case 3
in: [150,20,100]
expected: 0
Starter codePython
def one_cycle_peak_fraction(t, peak_step, total):
# Your code here
pass3 test cases · run your code against them in the editor