A drum sample pad stores each sound as a clip of N samples and lets a performer apply effects one after another. The clip always keeps its length N: whatever is pushed past either end is lost, and any new gap is filled with silence (0). The pad has two effects:
("delay", d): shift the sounddsamples later. The new clip isy[k] = x[k - d]when0 <= k - d < N, andy[k] = 0otherwise. A negativedshifts the sound earlier (an advance).("reverse", 0): play the clip backwards,y[k] = x[N - 1 - k]. The number is ignored.
Write edit_clip(x, ops) that applies the operations in ops in order, each to the result of the one before, and returns the final clip. Do not change x.
Examples
Input: x = [1, 2, 3, 4, 5], ops = [("delay", 2)]
Output: [0, 0, 1, 2, 3]
Explanation: the sound starts two samples later; the 4 and 5 fall off the end.
Input: x = [1, 2, 3, 4, 5], ops = [("reverse", 0), ("delay", 1)]
Output: [0, 5, 4, 3, 2]
Input: x = [1, 2, 3, 4, 5], ops = [("delay", 1), ("reverse", 0)]
Output: [4, 3, 2, 1, 0]
Explanation: the same two effects in the other order give a different clip.
Constraints
- a shift of
Nsamples or more in either direction leaves only silence - a list
[kind, number]is accepted in place of a tuple for each operation
Goals
- Delay or advance a signal by moving its samples and filling the gap with zeros
- Reverse a signal in time with the index rule y[k] = x[N - 1 - k]
- See that the order of operations changes the result