As described in this question:
Dropsort, designed by David Morgan-Mar, is an example of a linear-time "sorting algorithm" that produces a list that is, in fact, sorted, but contains only some of the original elements. Any element that is not at least as large as the maximum of the elements preceding it is simply removed from the list and discarded.
To use one of their test cases, an input of {1, 2, 5, 4, 3, 7}
yields {1, 2, 5, 7}
, as 4
and 3
are both dropped for being smaller than the previously "sorted" value, 5
.
We don't want "sorting" algorithms, we want them to be the real deal. Therefore, I want you to write a program that, given a list of numbers, outputs a list of DropSorted lists (to be a complete sorting algorithm, we would need to merge these lists, but merging two sorted lists has been done before, and asking you to do it again is pretty much asking two questions, so this question is specifically the "splitting" step of our complete DropSort).
The arrangement and content of our lists is crucial, however. The output of your program must be equivalent to the output of a DropSort, followed by a DropSort of the discarded values, and so on until you have only have a list of sorted chains. Again, borrowing the existing test suite (and adding two more):
Input -> Output
{1, 2, 5, 4, 3, 7} -> {{1, 2, 5, 7}, {4}, {3}}
{10, -1, 12} -> {{10, 12}, {-1}}
{-7, -8, -5, 0, -1, 1} -> {{-7, -5, 0, 1}, {-8, -1}}
{9, 8, 7, 6, 5} -> {{9}, {8}, {7}, {6}, {5}}
{10, 13, 17, 21} -> {{10, 13, 17, 21}}
{10, 10, 10, 9, 10} -> {{10, 10, 10, 10}, {9}} //Note equivalent values aren't dropped
{5, 4, 3, 8, 7, 6} -> {{5, 8}, {4, 7}, {3, 6}}
{0, 2, 5, 4, 0, 7} -> {{0, 2, 5, 7}, {4}, {0}}
You may assume the input is non-empty.
This is code-golf, so standard rules apply!
[5, 4, 3, 8, 7, 6] -> [5, 8], [4,3,7,6]
? \$\endgroup\${3,4,5,3,4,5,3,4,5}
result in{{3,4,5,5,5},{3,4,4},{3}}
? \$\endgroup\$