Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Reverse Every Ascending by kudinov.feodor
def reverse_ascending(items):
start, end = 0, 1
while end < len(items):
if items[end - 1] < items[end]:
end += 1
continue
yield from reversed(items[start:end])
start, end = end, end + 1
yield from reversed(items[start:end])
# print("Example:")
# print(list(reverse_ascending([1, 2, 3, 4, 5])))
#
# # These "asserts" are used for self-checking
# assert list(reverse_ascending([1, 2, 3, 4, 5])) == [5, 4, 3, 2, 1]
assert list(reverse_ascending([5, 7, 10, 4, 2, 7, 8, 1, 3])) == [
10,
7,
5,
4,
8,
7,
2,
3,
1,
], list(reverse_ascending([5, 7, 10, 4, 2, 7, 8, 1, 3]))
assert list(reverse_ascending([5, 4, 3, 2, 1])) == [5, 4, 3, 2, 1]
assert list(reverse_ascending([])) == []
assert list(reverse_ascending([1])) == [1]
assert list(reverse_ascending([1, 1])) == [1, 1]
assert list(reverse_ascending([1, 1, 2])) == [1, 2, 1]
print("The mission is done! Click 'Check Solution' to earn rewards!")
March 13, 2023