Это правильно?
def endzo(x, trough, peak, i, p, f, l, r, s, n):
n = p + 1
if abs(f) == 1:
if f == 1:
s[n] = peak
else:
s[n] = trough
else:
s[n] = (trough + peak) / 2
return x, trough, peak, i, p, f, l, r, s, n
def maxzo(x, trough, peak, i, p, f, l, r, s, n):
f = f + 1
while i < len(x):
i = i + 1
if i == (len(x) - 1):
x, trough, peak, i, p, f, l, r, s, n = endzo(x, trough, peak, i, p, f, l, r, s, n)
else:
if x[i] > peak:
peak = x[i]
else:
if peak - x[i] >= r:
p = p + 1
s[p] = peak
trough = x[i]
x, trough, peak, i, p, f, l, r, s, n = minzo(x, trough, peak, i, p, f, l, r, s, n)
return x, trough, peak, i, p, f, l, r, s, n
def minzo(x, trough, peak, i, p, f, l, r, s, n):
f = -1
while i < len(x):
i = i + 1
if i == (len(x) - 1):
x, trough, peak, i, p, f, l, r, s, n = endzo(x, trough, peak, i, p, f, l, r, s, n)
else:
if x[i] < trough:
trough = x[i]
else:
if x[i] - trough >= r:
p = p + 1
s[p] = trough
peak = x[i]
x, trough, peak, i, p, f, l, r, s, n = maxzo(x, trough, peak, i, p, f, l, r, s, n)
return x, trough, peak, i, p, f, l, r, s, n
x = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3]
trough = x[0]
peak = x[0]
i = -1
p = 0
f = 0
l = len(x) - 1
r = 1
s = []
n = 0
while i <= l:
i = i + 1
if i == l:
x, trough, peak, i, p, f, l, r, s, n = endzo(x, trough, peak, i, p, f, l, r, s, n)
else:
if x[i] > peak:
peak = x[i]
if peak - trough >= r:
s[p] = trough
x, trough, peak, i, p, f, l, r, s, n = maxzo(x, trough, peak, i, p, f, l, r, s, n)
else:
if x[i] < trough:
trough = x[i]
if peak - trough >= r:
s[p] = peak
x, trough, peak, i, p, f, l, r, s, n = minzo(x, trough, peak, i, p, f, l, r, s, n)
print(s)