FWIW, here is my solution. I think it is grokable and does not rely on one knowing complex python, I think even someone without Python knowledge would understand what is going on: def order_values(value, prev): """ Compare value and prev, returns, -1, 0, 1 depending on the relative ordering. """ return int(value > prev) - int(prev > value) def monotonic_increasing(seq): """ Given a sequence of elements, detect the in…
def monotonic_direct(seq):
prev_value = None
prev_dir = 0 # 0 for increasing or decreasing, 1 for increasing, -1 for decreasing
group = []
#print("Run", seq)
for value in seq:
#print(prev_dir, prev_value, value)
if not group:
# Can only get here with the first element
prev_value = value
group.append(value)
continue
if prev_dir == 0:
# Undecided order
if prev_value